Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define MAX_COUNT 10
  6.  
  7. int main() {
  8.     FILE *fp;
  9.     int i, num;
  10.     srand(time(NULL));
  11.  
  12.     fp = fopen("C:\\Users\\Toby\\Desktop\\rand.txt", "w");
  13.  
  14.     if (fp == NULL) {
  15.         printf("開起失敗");
  16.         return -1;
  17.     }
  18.  
  19.     i = 0;
  20.     num = (rand() % 64) + 1;
  21.     while (i < MAX_COUNT - 1) {
  22.         printf("%d, ", num);
  23.         fprintf(fp, "%d, ", num);
  24.         num = (rand() % 64) + 1;
  25.         i++;
  26.     }
  27.     printf("%d\n", num);
  28.     fprintf(fp, "%d\n", num);
  29.     printf("寫入完成\n");
  30.  
  31.     fclose(fp);
  32.     system("pause");
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement