0
How to find even or odd number
I'm beginniner plzz help me
4 odpowiedzi
+ 11
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter the any number: ";
cin >> n;
if ( n % 2 == 0)
cout << n << "\ngiven no is even.";
else
cout << n << "\ngiven no is odd.";
return 0;
}
+ 11
Same result using bitwise AND operator as the odd checker.
#include<iostream>
using namespace std;
int main ()
{
int n = 0;
cout << "Number is: "; cin >> n;
if (n & 1) cout << "Odd.\n";
else cout << "Even.\n";
}
0
thnks