本题要求编写程序,将给定的n个整数存入数组中,将数组中的这n个数逆序存放,再按顺序输出数组中的元素。
输入格式:
输入在第一行中给出一个正整数n(1≤n≤10)。第二行输入n个整数,用空格分开。
输出格式:
在一行中输出这n个整数的处理结果,相邻数字中间用一个空格分开,行末不得有多余空格。
输入样例:
4
10 8 1 2
这里是引用
输出样例:
2 1 8 10
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int i;
int a[10];
for(i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
int j;
int t;
for(j = 0; j < n / 2; j++)
{
t = a[j];
a[j] = a[n-1-j];
a[n-1-j] = t;
}
printf("%d", a[0]);
for(j = 1; j < n; j++)
{
printf(" %d", a[j]);
}
return 0;
}
2856

被折叠的 条评论
为什么被折叠?



