您的位置:首页 > 编程语言 > C语言/C++

c语言数组的逆序

2014-08-16 14:42 274 查看
include <stdio.h>
#include <stdlib.h>
#define M 10
#include <time.h>

int main(int argc, const char * argv[])
{

int i;
int j;
int t=0;
int tmp;
int n;
int a[M]={};
srand(time(NULL));

for (i=0; i<M; i++)
{
a[i]=rand()%100;
printf("%d  ",a[i]);
}
printf("\n");
//逆序
for (i=0; i<M/2; i++) {

tmp=a[i];
a[i]=a[M-i-1];
a[M-i-1]=tmp;
}
printf("\n");
//输出
 for (i=0; i<M; i++) {
printf("%d  ",a[i]);
}
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: