0
- Create an algorithm that contains an integer vector. Then, your algorithm should generate two more vectors. The first vector must store the numbers of the initial vector in ascending order and the second must store the values of the initial vector in descending order.
code:
#include <iostream>
using namespace std;
int main()
{
int vetor[5] = {8, 2, 7, 3, 6};
int cresc[5] = {vetor[0], vetor[1], vetor[2], vetor[3], vetor[4]};
int decre[5] = {vetor[0], vetor[1], vetor[2], vetor[3], vetor[4]};
for(int i = 0; i < 5; i++){
for(int j = 0; j < (5 - 1); j++){
if(cresc[i] < cresc[j]){
int aux = cresc[i];
cresc[i] = cresc[j];
cresc[j] = aux;
}
}
}
for(int a = 0; a < 5; a++){
for(int b = 0; b < (5 - 1); b++){
if(decre[a] > decre[b]){
int aux2 = decre[b];
decre[b] = decre[a];
decre[a] = aux2;
}
}
}
for(int x = 0; x < 5; x++){
cout << "vetor crescente[" << x << "]: " << cresc[x] << "" << endl;
}
cout << "--------------" << endl;
for(int z = 0; z < 5; z++){
cout << "vetor decrescente[" << z << "]:" << decre[z] << endl;
}
return 0;
}
You need to see if there are any statements that require anything, there are a few that diminish a little, but it may not be the intention to do so.
– Maniero
Careful, c and c++ are completely different languages. Writing in one language does not mean it will work in the other. By the way, your program does not work with a C compiler
– user5299