C Language Programming topic (II)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.