C语言实验——数组逆序
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
有n个整数,使其最后m个数变成最前面的m个数,其他各数顺序向后移m(m < n < 100)个位置。
Input
输入数据有2行,第一行的第一个数为n,后面是n个整数,第二行整数m。
Output
按先后顺序输出n个整数。
Example Input
5 1 2 3 4 5 2
Example Output
4 5 1 2 3
Hint
Author
参考代码
#include<stdio.h>
int main()
{
int a[100];
int m,n;
int temp;
int i,j;
scanf("%d",&n);
for(i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&m);
for(i = 0; i < m; i++)
{
temp = a[n-1];
for(j = n - 1; j > 0; j--)
{
a[j] = a[j-1];
}
a[0] = temp;
}
for(i = 0; i < n; i++)
{
if(i == n - 1)
printf("%d\n",a[i]);
else
printf("%d ",a[i]);
}
return 0;
}