First, your example does not compile because a }
is missing. Look how it looks when properly indented:
#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 have forgotten printf
and }
before system("pause");
. So this 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 that suits you 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 it fills it in the reverse order:
scanf("%d", &num[5 - i]);