首页 > 代码库 > 数组反转

数组反转

#include <stdio.h>
int main(void)
{
    int a[11] = {111,20,123,4543,556,34,5,54,43,234,53};
    int i ;
    for(i=0;i<11;i++){
      printf("%d\t",a[i]);
    }
    printf("\n");
    for(i=0;i<=4;i++){
      int tmp = a[i];
      a[i]= a[10-i];
      a[10-i] = tmp;
    }
    
    for(i=0;i<11;i++){
       printf("%d\t",a[i]);
    }
    printf("\n");
    
    int min=0;
    int max =10;
    
    while(min<max){
     int tmp = a[min];
     a[min] = a[max];
     a[max] = tmp;
     min++;
     max--;
    }
    for(i=0;i<11;i++){
       printf("%d\t",a[i]);
    }
    printf("\n");
    return 0;
}

 

数组反转