数组逆序输出

来源:互联网 发布:vs2015打开数据库 编辑:程序博客网 时间:2024/05/17 22:53
#include <stdio.h>/***数组逆序****/ #define N 100int main(){    int i,j,n,t;    int a[N];        printf("Please input the array length:");    scanf("%d",&n);        if(n > N)    {         printf("The length you put has overflowed!\n");         exit(0);    }    printf("Please input the %d number:\n",n);        for(i = 0; i < n; i++)        scanf("%d",&a[i]);            /******开始交换**********/        for(i = 0,j = n - 1; i < j; i++,j--)    {          t = a[i];          a[i] = a[j];          a[j] = t;    }      /*****输出交换后的数组*********/     for(i = 0; i < n; i++)    printf("%d\t",a[i]);         return 0;}