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
#include<stdio.h>
int main()
{
int a, b, c[100], d;
scanf("%d", &a);
for(b=0;b<a;b++)
{
scanf("%d", &c[b]);
}
scanf("%d", &d);
for(b=0;b<d;b++)
{
printf("%d ",c[a-d+b]);
}
for(b=0;b<(a-d);b++)
{
printf("%d%s", c[b],b==(a-d-1)?"":" ");
}
return 0;
}