結果の表示は文字の配置も含めて以下のようになるものとし,1行目に必ず 学生番号を表示するようにすること.また,末尾にハイフンによるラインを引い ておくこと.
必ず異なる二つの数にするのは現時点では大変なので,確率的に大体異なる数と なる程度の処理を考えてください.
My student number: s104099 Two different numbers: 4 and 5 ----------------------------------- |
授業で説明したように,else や && || などの使用はしない でプログラムを組んで下さい.
注意
/* ************************************************** */ /* */ /* 情報科学演習 C6 C7 */ /* レポート課題 */ /* 2011.5.9 */ /* */ /* ************************************************** */ /* */ /* 学生番号: */ /* */ /* 氏名: */ /* */ /* ************************************************** */ /* */ /* この行以降に解答のプログラムを書くこと */ #include <stdio.h> #include <stdlib.h> #include <time.h> main() { srand((unsigned) time(NULL)); int num1, num2; num1 = rand() % 5 + 1; num2 = rand() % 5 + 1; if(num1==num2) num2 = rand() % 5 + 1; if(num1==num2) num2 = rand() % 5 + 1; if(num1==num2) num2 = rand() % 5 + 1; if(num1==num2) num2 = rand() % 5 + 1; printf("Two different numbers: %d and %d\n", num1, num2); return(0); } |