My student number: s154099 Number of head: 0 1 2 3 4 5 6 7 8 9 10 Frequency: 1 2 1 9 19 27 21 10 8 2 0 -------------------------------------- |
解答用紙を使用する際には,まず,科目名の不要な方を削除してください.また,学生番号と名前の記入も忘れないでください.さらに,解答用紙自体がC言語のプログラムとなっていますので, cc コマンドを実行して,コンパイルエラーの無いことを確認してから提出してください. 指定の解答用紙を使用していない,コンパイルエラーが出る,実行時に警告が出る,学生番号と名前が無い,というような答案は提出されても採点しません.注意してください. |
/* ************************************************** */ /* */ /* プログラミング入門 情報科学演習C7 */ /* レポート課題 */ /* 2015.12.21 */ /* */ /* ************************************************** */ /* */ /* 学生番号: */ /* */ /* 氏名: */ /* */ /* ************************************************** */ /* */ /* この行以降に解答のプログラムを書くこと */ #include <stdio.h> #include <stdlib.h> #include <time.h> main() { srand((unsigned) time(NULL)); int i, j, coin[11], count; printf("My student number: s154099\n\n"); for(i=0; i<=10; i++) coin[i] = 0; for(i=1; i<=100; i++){ count = 0; for(j=1; j<=10; j++) count += rand() % 2; coin[count]++; } printf("Number of head: "); for(i=0; i<=10; i++) printf(" %2d ", i); printf("\nFrequency: "); for(i=0; i<=10; i++) printf(" %2d ", coin[i]); printf("\n\n--------------------------------------\n\n"); return(0); } |