#include <stdio.h>
int main(int argc, char *argv[])
{
int a[10] = {1,2,3,4,5,6,7,8,9,10};
int n,temp,i,j,k;
for ( i = 0; i < 10; ++i)
{
printf("%d ",a[i]);
}
printf("\n");
printf("请输入一个十以内的数值:");
scanf("%d",&n);
printf("数组前%d个元素倒置结果为:\n", n);
for ( k = 0; k < n/2; ++k)
{
temp=a[k];
a[k]=a[n-k-1];
a[n-k-1]=temp;
}
for ( j = 0; j < n; ++j)
{
printf("%d ",a[j]);
}
printf("\n");
return 0;
}
c语言定义数组int a[10] = {1,2,3,4,5,6,7,8,9,10} 输入n值,把数组的前n个元素倒置并打印
最新推荐文章于 2024-09-27 21:18:21 发布