From 203892796893d2229b4d4b73f82c9b10ba624246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Waldson=20Patr=C3=ADcio?= <waldsonpatricio@gmail.com> Date: Tue, 3 Mar 2020 20:01:31 -0300 Subject: [PATCH] =?UTF-8?q?Move=20array=20de=20n=C3=BAmeros=20pra=20free?= =?UTF-8?q?=20store=20e=20recebe=20N=20a=20partir=20da=20linha=20de=20coma?= =?UTF-8?q?ndo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula3/main.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 aula3/main.cpp diff --git a/aula3/main.cpp b/aula3/main.cpp new file mode 100644 index 0000000..7b864fe --- /dev/null +++ b/aula3/main.cpp @@ -0,0 +1,35 @@ +#include <iostream> +#include <cstdlib> + +int main(int argc, char* argv[]) { + if (argc <= 1) { + std::cout << "Usage: " << argv[0] << " <number of elements>\n"; + return -1; + } + + size_t n = std::atoi(argv[1]); + + + int* numeros = new int[n]; + + for (size_t i = 0; i < n; ++i) { + numeros[i] = rand() % 100; + } + + //ornedar + + for (size_t i = 0; i < n - 1; ++i) { + for (size_t j = i + 1; j < n; ++j) { + if (numeros[j] < numeros[i]) { + int tmp = numeros[j]; + numeros[j] = numeros[i]; + numeros[i] = tmp; + } + + } + } + + + delete[] numeros; +} + -- GitLab