Advertisement
kk258966

5/14 C++練習二

May 14th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int main(void)
  5. {
  6.     int i,max=100,min=200;
  7.     int num,no[1000];
  8.     int count=0;
  9.     srand(time(NULL));
  10.  
  11. ///////////////////陣列歸零//////////////////////
  12. for (i=0;i<=999;i++)
  13. no[i]=0;
  14.  
  15. //////////////////隨機產生重複數字//////////////
  16.  
  17. while (count<31)
  18. {
  19.       count++;
  20.       no[count]=rand()%1000;
  21. }
  22.  
  23. /////////////////寫檔/////////////////////////
  24.  
  25. FILE *written;
  26. written=fopen("random.txt","w");
  27. printf("開出的號碼是:\n");
  28. for(i=1;i<=count;i++)
  29. {
  30. if(no[i]>=100 && no[i]<=200)
  31. {
  32.               printf("%d\n",no[i]);
  33.               fprintf(written,"%d ",no[i]);
  34. }
  35. }
  36.  close(written);
  37.  
  38.  printf("寫檔完成\n");
  39.  
  40.  
  41.  
  42.    
  43.     system("pause");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement