C++ - Loops to Read Numbers and Check Odd or Even Number
I have given here the code to read set of integers and display whether odd or even number
Source Code
int main()
{
std::cout << "Program to find ODD or Even Number\n";
while(1)
{
int n = 0;
std::cout << "\nEnter a number(-1 for Exit): ";
std::cin >> n;
if( n == -1)
break;
if((n % 2) == 0)
{
std::cout << n << " is a EVEN number.\n";
}
else
{
std::cout << n << " is a ODD number.\n";
}
}
return 0;
}
Output
Program to find ODD or Even Number
Enter a number(-1 for Exit): 1
1 is a ODD number.
Enter a number(-1 for Exit): 2
2 is a EVEN number.
Enter a number(-1 for Exit): 3
3 is a ODD number.
Enter a number(-1 for Exit): 4
4 is a EVEN number.
Enter a number(-1 for Exit): 5
5 is a ODD number.
Enter a number(-1 for Exit): 6
6 is a EVEN number.
Enter a number(-1 for Exit): 7
7 is a ODD number.
Enter a number(-1 for Exit): -1
|