最後まで表示できた場合の例
My student number: s154099 Random numbers: 2 10 17 24 26 -------------------------------- |
途中で打ち切られた場合の例
My student number: s154099 Random numbers: 25 28 -- Sorry! Impossible to print all. -------------------------------- |
解答用紙を使用する際には,まず,科目名の不要な方を削除してください.また,学生番号と名前の記入も忘れないでください.さらに,解答用紙自体がC言語のプログラムとなっていますので, cc コマンドを実行して,コンパイルエラーの無いことを確認してから提出してください. 指定の解答用紙を使用していない,コンパイルエラーが出る,実行時に警告が出る,学生番号と名前が無い,というような答案は提出されても採点しません.注意してください. |
/* ************************************************** */ /* */ /* プログラミング入門 情報科学演習C7 */ /* レポート課題 */ /* 2015.11.16 */ /* */ /* ************************************************** */ /* */ /* 学生番号: */ /* */ /* 氏名: */ /* */ /* ************************************************** */ /* */ /* この行以降に解答のプログラムを書くこと */ #include <stdio.h> #include <stdlib.h> #include <time.h> main() { srand((unsigned) time(NULL)); int n1, n2, n3, n4, n5; printf("My student number: s154099\n\n"); printf("Random numbers: "); n1 = rand() % 30 + 1; printf("%d ", n1); if(n1<27){ n2 = rand() % (30-n1) + n1 + 1; printf("%d ", n2); if(n2<28){ n3 = rand() % (30-n2) + n2 + 1; printf("%d ", n3); if(n3<29){ n4 = rand() % (30-n3) + n3 + 1; printf("%d ", n4); if(n4<30){ n5 = rand() % (30-n4) + n4 + 1; printf("%d ", n5); } else printf(" -- Sorry! Impossible to print all."); } else printf(" -- Sorry! Impossible to print all."); } else printf(" -- Sorry! Impossible to print all."); } else printf(" -- Sorry! Impossible to print all."); printf("\n\n--------------------------------\n\n"); return(0); } |