Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define MAX_COUNT 10
- int main() {
- FILE *fp;
- int i, num;
- srand(time(NULL));
- fp = fopen("C:\\Users\\Toby\\Desktop\\rand.txt", "w");
- if (fp == NULL) {
- printf("開起失敗");
- return -1;
- }
- i = 0;
- num = (rand() % 64) + 1;
- while (i < MAX_COUNT - 1) {
- printf("%d, ", num);
- fprintf(fp, "%d, ", num);
- num = (rand() % 64) + 1;
- i++;
- }
- printf("%d\n", num);
- fprintf(fp, "%d\n", num);
- printf("寫入完成\n");
- fclose(fp);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement