0
I created a code that takes a certain number set by the user, and makes the separation of pairs and odd, until then I was able to do, my problem is to put the numbers in ascending order so that the code looked more visually at the time of printing, printing both pairs and odd. follows the code as this currently.
#include <stdio.h>
#include <stdlib.h>
int main() {
int quantVetor = 0,vetPar[100],vetImpar[100],quantPar = 0,quantImpar = 0,posicao[100],i;
printf("Digite o tamanho do vetor que deseja\n");
scanf("%d",&quantVetor);
//
printf("Atribua os valores ao vetor\n");
for (i = 0; i < quantVetor ; i++) {
scanf("%d", &posicao[i]);
if(posicao[i] % 2 == 0){
vetPar[quantPar]=posicao[i];
quantPar++;
} else{
vetImpar[quantImpar]=posicao[i];
quantImpar++;
} // fim else
} // fim for
printf("\n\n");
for (i = 0; i < quantPar; i++) {
printf("par %d\n\n",vetPar[i] );
} // fim for
for (int i = 0; i < quantImpar; i++) {
printf("impar %d\n\n",vetImpar[i] );
} // fim for
return 0;
}
As I would like to leave the exit: Pairs : 2,4,6 Odd: 1,3,5 and so on. (no need to be side by side but if you have how to do would like to know how it is).
Search by sorting algorithms. There is plenty of material on the internet.
– anonimo