Advertisement
kk258966

5/7 C++ 練習二

May 7th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int main(void)
  5. {
  6.     FILE *written;
  7.     int a,i;
  8.     written=fopen("random.txt","w");
  9.     srand(time(NULL));
  10.    
  11.     for(i=1;i<=20;i++)
  12.     {
  13.         a=rand()%100;
  14.         printf("%d ",a);
  15.         fprintf(written,"%d ",a);
  16.     }
  17.     fclose(written);
  18.     printf("\n=================================\n");
  19.     FILE *read;
  20.     int b;
  21.     read=fopen("random.txt","r");
  22.     printf("\n開出號碼大於50的有:\n");
  23.    
  24.  
  25.     while((fscanf(read,"%d",&b))!=EOF)
  26.     {
  27.          if(b>50)
  28.          {                            
  29.          printf("%d\n",b);
  30.          }
  31.                                      
  32.     }
  33.  
  34.  
  35.     system("pause");
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement