零基礎學C/C++24——判斷奇偶數
題目描述
輸入一個整數,判斷是奇數還是偶數
輸入
輸入1個正整數
輸出
如果是偶數,輸出even否則輸出odd
樣例輸入
2
樣例輸出
even
c++版本一
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
if(n%2==0)printf("even\n");
else if(n%2!=0)printf("odd\n");
}
}
c++版本二(位運算)
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
cin>>n;
if(n&1)cout<<"odd"<<endl;
else cout<<"even"<<endl;
}