First, your example does not compile, because it lacks a }. Look how he gets when properly devised:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, num[6];
printf("Digite 6 numeros inteiros.\n");
for (i = 0; i < 6; i++) {
printf("Digite o %d valor: ", i + 1);
scanf("%d", &num[i]);
}
system("cls");
for (i = 0; i < 6; i++) {
system("pause");
return 0;
}
I suppose you’ve forgotten one printf and a } before the system("pause");. So that would be the code (printing in direct order):
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, num[6];
printf("Digite 6 numeros inteiros.\n");
for (i = 0; i < 6; i++) {
printf("Digite o %d valor: ", i + 1);
scanf("%d", &num[i]);
}
system("cls");
for (i = 0; i < 6; i++) {
printf("O %d valor eh: ", num[i]);
}
system("pause");
return 0;
}
You are reading the 6 numbers correctly. Then, the solution would be simple. I have two alternatives, choose the one you find best.
Alternative 1:
Just print the numbers on the screen in reverse order. For this, you iterate the array (in the second for) in reverse order:
for (i = 5; i >= 0; i--) {
Alternative 2:
You iterate the array in the correct order, but fill it in the reverse order:
scanf("%d", &num[5 - i]);
I think the reverse order is this: Input:
1 3 5 7 9Exit:9 7 5 3 1– user3603
Print using the for no array back to front:
for(i=5; i>=0; i--){ num[i];– KaduAmaral