char hand[3][6] = {"Gu", "Choki", "Pa"}; char result[3][20] = {"Aiko", "Winner is computer!", "Winner is you!"}; |
My student number: s164099 You: Gu Computer: Gu Aiko You: Choki Computer: Pa Winner is you! --------------------------------- |
なお,結果の出力では必ず最初の行に自分の学生番号を,最後にハイフンによるラインをつけること.無い場合には減点するので注意.
文字列ごと表示させるので, printf では %s を使います.
解答用紙を使用する際には,まず,科目名の不要な方を削除してください.また,学生番号と名前の記入も忘れないでください.さらに,解答用紙自体がC言語のプログラムとなっていますので, cc コマンドを実行して,コンパイルエラーの無いことを確認してから提出してください. 指定の解答用紙を使用していない,コンパイルエラーが出る,実行時に警告が出る,学生番号と名前が無い,というような答案は提出されても採点しません.注意してください. |
/* ************************************************** */ /* */ /* プログラミング入門 情報科学演習C7 */ /* レポート課題 */ /* 2017.01.16 */ /* */ /* ************************************************** */ /* */ /* 学生番号: */ /* */ /* 氏名: */ /* */ /* ************************************************** */ /* */ /* この行以降に解答のプログラムを書くこと */ #include <stdio.h> #include <stdlib.h> #include <time.h> main() { srand((unsigned) time(NULL)); int h1, h2, diff = 0; char hand[3][6] = {"Gu", "Choki", "Pa"}; char result[3][20] = {"Aiko", "Winner is computer!", "Winner is you!"}; printf("My student number: s164099\n\n"); while(diff==0){ h1 = rand() % 3 + 3; h2 = rand() % 3; diff = (h1 - h2) % 3; printf("You: %s\n", hand[h1%3]); printf("Computer: %s\n", hand[h2]); printf("%s\n\n", result[diff]); } printf("---------------------------------\n\n"); return(0); } |