这个应该可以凑合着用:
#include
#include "stdlib.h"
#include "time.h"
#define N 1000
int main(void){
int i,k,t,n;
srand((unsigned)time(NULL));
for(n=N>>1,k=i=0;it=rand()%10;
printf(++k%8 ? "%5d%5d" : "%5d%5d\n",10-t,10+t);
}
if(N&1)
printf("%5d",10);
if(k%8)
printf("\n");
return 0;
}
要写得质量略为高一点的话可以如下:
#include
#include "stdlib.h"
#include "time.h"
#define N 1000
int main(void){
int i,k,t,a[N];
srand((unsigned)time(NULL));
for(i=0;ia[i]=10+(t=rand()%10);
a[i+1]=10-t;
}
if(N&1)
a[N-1]=10;
for(k=0,i=N-1;i>=0;i--){
printf(++k%16 ? "%5d" : "%5d\n",a[t=rand()%(i+1)]);
a[t]^=a[i],a[i]^=a[t],a[t]^=a[i];
}
if(k%16)
printf("\n");
return 0;
}