#define random(x)(rand()%x)
#define N 10
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void zhizhen(int a[],int n)
{
int temp;
int *low,*high;
for(low=&a[0],high=&a[n-1];low<high;low++,high--)
{temp=*high;*high=*low;*low=temp;}
}
void xiabiao(int a[],int n)
{
int i,j,t;
for(i=0,j=n-1;i<j;i++,j--)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
void print(int a[],int q)
{
int i;
if(q==0)
{
printf("用指针法重排:\n");
for(i=0;i<10;i++)
printf("%5d",a[i]);
}
if(q==1)
{
printf("用下标法重排:\n");
for(i=0;i<10;i++)
printf("%5d",a[i]);
}
}
void main()
{
FILE *f1,*f2;
int x,m[N], i;
if((f1=fopen("123.txt","r"))==NULL)
{printf("不能打开此文件:%s\n","123.txt");exit(0);}
//m[N]=fopen("123.txt","r");
for(i = 0; i < N; i++)
fscanf(f1,"%d",&m[i]);
x=1+random(1);
if(x==0) {zhizhen(m,
N);print(m, x);}
if(x==1) {xiabiao(m, N);print(m, x);}
fclose(f1);
f2=fopen("456.tet","w");
for(i = 0; i < N-1; i++)
fprintf(f2,"%d ",m[i]);
fclose(f1);
}
为什么随机的会没有用啊。。。