To write a program implementation:
(1) Generate 300 random four-digit numbers, and then save these 4 digits to Rand.txt;
(2) The number of single digits and thousands in the statistical Rand.txt equals to 10 digits and the sum of the Hundred;
(3) The number that satisfies the condition 2 is sorted in reverse order to output it to out.txt.
1#include <stdio.h>2#include <stdlib.h>3#include <time.h>4 5 #defineMaxnum 99996 #defineMinnum 10007 #defineMAXLINE 3008 #defineDIR "D:\\rand.txt"9 Ten voidGetrand (); One voidWritedat (); A voidReaddat (); - voidFinddat (); - the Main () - { -printf"Hellow fjk\n"); - Getrand (); + Finddat (); - } + A voidGetrand () at { - intA[maxline]; - inti; -Srand ((unsignedint) Time (NULL)); - - for(i=0; i<maxline;i++) inA[i]=rand ()% (maxnum-minnum+1)+Minnum; - Writedat (maxline,a); to } + - voidWritedat (intMaxlineintrand[]) the { *FILE *FP; $ inti;Panax Notoginseng -Fp=fopen (DIR,"w+"); the for(i=0; i<maxline;i++) +fprintf (FP,"%d\n", Rand[i]); A fclose (FP); the } + - voidReaddat (intMaxlineinttemp[]) $ { $FILE *FP; - inti; -Fp=fopen (DIR,"R"); the for(i=0; i<maxline;i++) - {WuyiFSCANF (FP,"%d",&temp[i]); theprintf"%d\n", Temp[i]); - } Wu fclose (FP); - } About $ voidFinddat () - { - intTemp[maxline],b[maxline],i,j,t,cnt=0; - intGe_wei,shi_wei,bai_wei,qian_wei; AFILE *FP; + the Readdat (maxline,temp); - for(i=0; i<maxline;i++) $ { thege_wei=temp[i]%Ten; theshi_wei=temp[i]%Ten/Ten; thebai_wei=temp[i]% +/ -; theqian_wei=temp[i]/ +; - in if((Ge_wei+qian_wei) > (bai_wei+Shi_wei)) the { theb[cnt]=Temp[i]; Aboutcnt++; the } the } theprintf"%d\n", CNT); + for(i=0; i<cnt-1; i++) - for(j=i+1; j<cnt;j++) the if(b[i]>B[j])Bayi { thet=B[i]; theb[i]=B[j]; -b[j]=T; - } the theFp=fopen ("D:\\out.txt","w+"); the for(i=0; i<cnt;i++) thefprintf (FP,"%d\n", B[i]); - fclose (FP); the}
C Language Programming topic (II)