char fc[4][10] = {"Barcelona", "Dortmund", "Liverpool", "Sanfrecce"}; |
4つのチームの内のどれか2つを選び,また,0〜3の範囲の整数を2つ乱数で発生させ,以下のように試合結果的に表示するプログラムを作成せよ.
My student number: s154099 Dortmund 3 - 2 Sanfrecce ---------------------------------- |
表示においては,最初の行に学生番号,最後にはハイフンによる線を出力するようにしてください.また,必ず解答用紙を使用し,解答用紙には学生番号と名前を記入してください.
/* ************************************************** */ /* */ /* プログラミング入門 情報科学演習C7 */ /* 小テスト */ /* 2016.01.18 */ /* */ /* ************************************************** */ /* */ /* 学生番号: */ /* */ /* 氏名: */ /* */ /* ************************************************** */ /* */ /* この行以降に解答のプログラムを書くこと */ #include <stdio.h> #include <stdlib.h> #include <time.h> main() { srand((unsigned) time(NULL)); int fc1, fc2; char fc[4][10] = {"Barcelona", "Dortmund", "Liverpool", "Sanfrecce"}; fc1 = rand() % 4; fc2 = fc1; while(fc1==fc2) fc2 = rand() % 4; printf("My student number: s154099\n\n"); printf("%s ", fc[fc1]); printf("%d - %d ", rand()%4, rand()%4); printf("%s\n", fc[fc2]); printf("\n----------------------------------\n"); return(0); } |