将数组中的数逆序存放

本题要求编写程序,将给定的n个整数存入数组中,将数组中的这n个数逆序存放,再按顺序输出数组中的元素。

输入格式:

输入在第一行中给出一个正整数n(1≤n≤10)。第二行输入n个整数,用空格分开。

输出格式:

在一行中输出这n个整数的处理结果,相邻数字中间用一个空格分开,行末不得有多余空格。

输入样例:

4
10 8 1 2

结尾无空行

输出样例:

2 1 8 10

结尾无空行

#include<stdio.h>
int main()
{
	int a[10], b[10];
	int i, j, n, count=0;
	scanf("%d", &n);
	for(i=0; i<n; i++)
		scanf("%d", &a[i]);
	for(j=n-1; j>=0; j--){
		b[count]=a[j];
		count++;
	}
	printf("%d", b[0]);
	for(i=1; i<n; i++)
		printf(" %d", b[i]);
		
	return 0;
}

 

おすすめ

転載: blog.csdn.net/m0_48888014/article/details/121111660