Program:
#include <iostream>
using namespace std;
int main() {
int num;
cout<<"Enter the number to check: ";
cin>>num;
if(num%2 != 0){
cout<<"The number "<<num<<" is odd!"<<endl;
}else{
cout<<"The number "<<num<<" is not odd!"<<endl;
}
return 0;
}
Output:1. First, I declare the variable
2. Then, I prompt the user to enter a number to check whether it is odd or not using
3. I check whether the number is odd or not using an if-else statement.
4. If the number is not divisible by 2, i.e., if the remainder of the division operation
5. If the number is divisible by 2, i.e., if the remainder of the division operation
6. Finally, I return 0 to indicate that the program has completed successfully.
num
.2. Then, I prompt the user to enter a number to check whether it is odd or not using
cout
and read it in using cin
.3. I check whether the number is odd or not using an if-else statement.
4. If the number is not divisible by 2, i.e., if the remainder of the division operation
num%2
is not equal to 0, then the number is odd. In that case, I print out a message saying "The number num
is odd!" using cout
.5. If the number is divisible by 2, i.e., if the remainder of the division operation
num%2
is equal to 0, then the number is not odd. In that case, I print out a message saying "The number num
is not odd!" using cout
.6. Finally, I return 0 to indicate that the program has completed successfully.
No comments:
Post a Comment