-1
I have to do the following exercise:
Read 3 whole values and order them in ascending order. At the end, show the values in ascending order, a blank line and then the values in sequence as read.
The sorting part of the numbers I got. I now need to display the index (counter) outside the for.
#include<stdio.h>
int main() {
int n, i, maior, menor, meio;
scanf("%d", &n);
maior = n; menor = n; meio = n;
for(i = 1; i <= 2; i++) {
scanf("%d", &n);
if (n > maior) {
maior = n;
} else if (n < menor) {
menor = n;
} else {
meio = n;
}
}
printf("%d\n", menor);
printf("%d\n", meio);
printf("%d\n", maior);
printf("\n");
return 0;
}
Your code reads the values but does not sort in ascending order as it is requested, when writing the numbers, both will be in the same order.
– Brumazzi DB
I imagined that the author of the question had no problem with the ordination, since he himself stated that it worked. : D
– mau humor
It’s that sorting 2 or 3 numbers is easy, but above said is not feasible with conditions, so it uses sorting algorithms. If in a VC response you can give solutions and improvements, this results in the quality of your response.
– Brumazzi DB