どれかの象限に入っている場合の例
My student number: s154099 Coordinates (x, y) = (2, -1) The point is in the 4th quadrant. ---------------------------- |
座標軸上の場合の例
MMy student number: s154099 Coordinates (x, y) = (1, 0) The point is on the x-axis. ---------------------------- |
表示区分は,どれかの象限,どちらかの座標軸上,および原点 (the origin) の3種類7パターンです.
解答用紙を使用する際には,まず,科目名の不要な方を削除してください.また,学生番号と名前の記入も忘れないでください.さらに,解答用紙自体がC言語のプログラムとなっていますので, cc コマンドを実行して,コンパイルエラーの無いことを確認してから提出してください. 指定の解答用紙を使用していない,コンパイルエラーが出る,実行時に警告が出る,学生番号と名前が無い,というような答案は提出されても採点しません.注意してください. |
/* ************************************************** */ /* */ /* プログラミング入門 情報科学演習C7 */ /* レポート課題 */ /* 2015.11.09 */ /* */ /* ************************************************** */ /* */ /* 学生番号: */ /* */ /* 氏名: */ /* */ /* ************************************************** */ /* */ /* この行以降に解答のプログラムを書くこと */ #include <stdio.h> #include <stdlib.h> #include <time.h> main() { srand((unsigned) time(NULL)); int x = rand() % 5 - 2; int y = rand() % 5 - 2; printf("My student number: s154099\n\n"); printf("Coordinates (x, y) = (%d, %d)\n", x, y); printf("The point is "); if(x>0 && y>0) printf("in the 1st quadrant.\n"); else if(x>0 && y<0) printf("in the 4th quadrant.\n"); else if(x<0 && y>0) printf("in the 2nd quadrant.\n"); else if(x<0 && y<0) printf("in the 3rd quadrant.\n"); else if(x!=0) printf("on the x-axis.\n"); else if(y!=0) printf("on the y-axis.\n"); else printf("on the origin.\n"); printf("\n----------------------------\n\n"); return(0); } |