Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h> //For random-number functions,atoi
- #include <string.h> //For strlen
- int main()
- {
- int j, k; //loop counter
- int r; //ramdom number
- int seed = 999; //学籍番号下三桁
- int cnt[10] = { 0 };
- int nmax; //最も発生した番号
- int cmax; //最も発生した番号の発生回数
- char id[101],name[1010]; printf("学籍番号と名前を入れてください。>"); scanf("%s %s", id, name);
- printf("学籍番号:%s ,名前:%s\n", id, name);
- seed = atoi(&id[strlen(id)-3]); //printf("seed=%d\n",seed);
- //Seed for random number
- srand(seed);
- //Make ramdom numbers
- for (k = 1; k <= 100000; k++) {
- r = rand() % 10;
- cnt[r]++;
- }
- //Display
- for (j = 0; j < 10; j++) {
- printf("%5d at Num. = %d\n", cnt[j], j);
- }
- puts("");
- //Search max number
- nmax = 0;
- cmax = cnt[0];
- for (j = 1; j < 10; j++) {
- if (cnt[j] > cmax) {
- cmax = cnt[j];
- nmax = j;
- }
- }
- printf("Max = %5d at Num. = %d\n", cmax, nmax);
- // 自分の学籍番号で何が何回出たか書いてください。
- //
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment