2 で完全に割り切れる数は、偶数と呼ばれます。 . 2 で完全に割り切らないものは 奇数 として知られています .
完全に割り切れるということは、割り算で余りが 0 になることを意味します。
アルゴリズム:
<オール>以下のコードは、ユーザーが入力した整数が偶数か奇数かをチェックします:
#include <iostream>
using namespace std;
int main()
{
int num;
//Input the number
cout<<"Enter an integer: ";
cin>>num;
if (num % 2 == 0)//check its divisibility with 2
cout<< num << " is even.";
else
cout<< num <<" is odd.";
return 0;
}
出力:
Enter an Integer:234
234 is even.