C language ordering a positive integer

200 in.dat positive integer in the file, and each having a number average between 1000-9999. ReadDat function () 200 which reads the number aa stored in the array. Please prepare function jsSort (), the function is a function of: the size requirements per the number of three in descending order, and then taken to meet this condition before the number 10 are sequentially stored in the array b, after if the three values ​​are equal, as was originally values ​​in ascending order. After calling the function WriteDat () output the results to a file out.dat in bb.

Example: Before treatment 9012 5,099,601,270,258,088

After treatment 8088 7025 6012 9012 5099
#include <stdio.h>

#include<string.h>

#include<conio.h>

int aa [200], bb [10];

void jsSort()

{

int i,j,data;

for(i=0;i<199;i++)

for(j=i+1;j<200;j++)

if(aa[i]%1000<aa[j]%1000||aa[i]%1000==aa[j]%1000&&aa[i]>aa[j])

{data=aa[i];aa[i]=aa[j];aa[j]=data;}

for(i=0;i<10;i++)

bb[i]=aa[i];

}

void main()

{

readDat();

jsSort ();

writeDat();

system(“pause”);

}

readDat()

{

FILE *in;

int i;

in=fopen(“in.dat”,“r”);

for(i=0; i<200; i++) fscanf(in,"%d,",&aa[i]);

fclose(in);

}

writeDat()

{ FILE *out;

int i;

clrscr();

out=fopen(“out.dat”,“w”);

for(i=0; i<10; i++){

printf(“i=%d,%d\n”,i+1,bb[i]);

fprintf(out,"%d\n",bb[i]);

}

fclose(out);

}

Published 239 original articles · won praise 3 · Views 3141

Guess you like

Origin blog.csdn.net/it_xiangqiang/article/details/105176955