问题描述
编写一个程序,读入一组整数(不超过20个),并把它们保存在一个整型数组中。当用户输入0时,表示输入结束。然后程序将把这个数组中的值按逆序重新存放,并打印出来。例如:假设用户输入了一组数据:7 19 -5 6 2 0,那么程序将会把前五个有效数据保存在一个数组中,即7 19 -5 6 2,然后把这个数组中的值按逆序重新存放,即变成了2 6 -5 19 7,然后把它们打印出来。 输入格式:输入只有一行,由若干个整数组成,中间用空格隔开,最末尾的整数为0。 输出格式:输出也只有一行,即逆序排列后的整数,中间用空格隔开,末尾没有空格。 输入输出样例
输入例子 1
7 19 -5 6 2 0
输出例子 1
2 6 -5 19 7
#include<bits/stdc++.h>
using namespace std;
int main()
{
int count,a[20],t;
for (count=0;;count++)
{
scanf("%d",&a[count]);
if (a[count]==0)
break;
}
for(int i=0;i<count/2;i++)
{
t = a[i];
a[i] = a[count-1-i];
a[count-1-i]=t;
}
for(int i=0;i<count;i++)
printf("%d ",a[i]);
return 0;
}