发布网友 发布时间:2024-08-17 07:37
共1个回答
热心网友 时间:2024-08-23 02:33
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 20
void main() { int a[N],i,j,k;
srand((unsigned int)time(NULL)); for ( i=0;i<N;i++ ) a[i]=rand()%100;
for ( i=0;i<N;i++ ) printf("%d ",a[i]); printf("\n");
for ( i=0;i<N-2;i+=2 ) for ( j=i+2;j<N;j+=2 ) if ( a[i]<a[j] ) {k=a[i];a[i]=a[j];a[j]=k;}
for ( i=1;i<N-1;i+=2 ) for ( j=i+2;j<N;j+=2 ) if ( a[i]>a[j] ) {k=a[i];a[i]=a[j];a[j]=k;}
for ( i=0;i<N;i++ ) printf("%d ",a[i]); printf("\n");
}