-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestao vetores 6.cpp
More file actions
56 lines (49 loc) · 1.08 KB
/
questao vetores 6.cpp
File metadata and controls
56 lines (49 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
using namespace std;
/*
Utilizando vetores, crie um programa que organize
uma quantidade qualquer de números inteiros fornecidos
pelo usuário da seguinte forma: primeiro os números
pares em ordem crescente e depois os números ímpares
em ordem decrescente.
*/
int main() {
int vetor[10];
int entrada;
int i, j, aux;
cout << "digite a entrada:" << endl;
for (i=0; i<10; i++) {
cin >> entrada;
vetor[i] = entrada;
}
cout << endl;
cout << "Ordem Crescente:" << endl;
for (i=0; i<10; i++) {
for (j=i+1; j<10; j++) {
if (vetor[i] > vetor[j]) {
aux = vetor[i];
vetor[i] = vetor[j];
vetor[j] = aux;
}
}
}
for (j=0; j<10; j++)
if (vetor[j]%2 == 0)
cout << vetor[j] << endl;
cout << endl;
cout << "Ordem Decrescente:" << endl;
for (i=0; i<10; i++) {
for (j=i+1; j<10; j++) {
if (vetor[j] > vetor[i]) {
aux = vetor[j];
vetor[j] = vetor[i];
vetor[i] = aux;
}
}
}
for (j=0; j<10; j++)
if (vetor[j]%2 != 0)
cout << vetor[j] << endl;
cout << endl;
return 0;
}