問題
今日の問題は以下のリンクから確認できます。
![](https://img.atcoder.jp/assets/atcoder.png)
ABC086A - Product
AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.
問題を要約するとa,bが標準入力されて、その積(Product)が奇数(Odd)か偶数(Even)なのかを判断して結果を出力してください。
サンプルコード
GitHub上にサンプルコードをアップしました。
https://github.com/mintson0517/AtCoder-Beginners-Selection/blob/main/AtCoder%20Beginners%20Selection/C/02.c
コードの解説
まず、#include <stdio.h>
は、標準入出力を行うためのヘッダーファイルをインクルードしています。
#include <stdio.h>
int main() {
処理を記述、、、、、
return 0;
}
int
は、整数型(intger)の変数 a
と b
を宣言しています。
int a, b;
scanf("%d %d", &a, &b); // aとbの値を入力
int product = a * b; // aとbの積を計算
scanf("%d %d", &a, &b);
は、2つの整数を入力します。int product = a * b;
は、変数 a
と b
の積を計算し、その結果を product
に代入しています。
// 積が偶数か奇数かを判定し、結果を出力
if (product % 2 == 0) {
printf("Even\n"); // 積が偶数の場合
} else {
printf("Odd\n"); // 積が奇数の場合
}
次にif構文を使用して、割る2をして割り切れたら偶数(Even)、割り切れなかった場合は奇数(Odd)を判断して出力してくれます。
最後に return 0;
が実行されて、プログラムが正常に終了します。