-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog13.cpp
More file actions
76 lines (56 loc) · 1.43 KB
/
prog13.cpp
File metadata and controls
76 lines (56 loc) · 1.43 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// problema do array
// Escreva um programa em C que preencha um vetor de 100 posições com os números de 1 a 100.
// A partir do vetor criado:
// imprima os números em ordem decrescente
// imprima somente os números pares
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(void)
{
int v[100]; // o vetor que contera 100 valores
int i,j; // subscritor para os vetores
int aux; // auxiliar no processo de ordenacao
srand(time(NULL)); // inicializa o gerador de numeros aleatorios
//sintaxe da funcao rand()
//ale = menor valor + rand() % (maior valor - menor valor)
//ale = 0 + rand() % (100-0);
// carregando o vetor com 100 numeros
i = 0;
while (i < 100)
{
v[i] = rand() % 1000; // ale eh o numero aleatorio gerado
i++;
}
// exibindo os pares
cout << "so os pares\n";
i = 0;
while (i < 100)
{
if (v[i] % 2 == 0)
cout << v[i] << "\t";
i++;
}
// ordenando pelo metodo bolha
for (i=0; i < 100; i++ )
{
for (j=i+1; j<100; j++)
{
if ( v[i] > v[j] )
{
aux = v[i];
v[i] = v[j];
v[j] = aux;
}
}
}
// exibindo os numeros em ordem decrecente
cout << "\nordem decrescente\n";
i = 99;
while (i >= 0)
{
cout << v[i] << "\t";
i--;
}
return 0;
}