C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++

Write a program to check if the number is even or odd. Take an integer input from the user, if it is even print "even", otherwise print "odd". Sample Input 25 Sample Output odd Attempt in comments

16th Sep 2021, 11:13 AM
Mando
Mando - avatar
4 Answers
+ 4
Mando dude what will be the number here (number%25)?? Check 25 or any other number for even or odd by taking its modulus with 2 like --> (25%2==0)cout<<"even"; else cout<<"odd"; Other way Martin mentioned is: int number=25; if(number & 1) cout<<"odd"; else cout<<"even";
16th Sep 2021, 1:09 PM
HK Lite
HK Lite - avatar
0
#include <iostream> using namespace std; int main() { int number; cin>>number; if (number<25) { cout << "even"; } else { cout << "odd"; } return 0; }
16th Sep 2021, 11:13 AM
Mando
Mando - avatar
0
So (number%25)?
16th Sep 2021, 12:04 PM
Mando
Mando - avatar
17th Sep 2021, 1:59 PM
Assaf Hillel
Assaf Hillel - avatar