write a program in c++ to enter 10 no. and print whether which no is odd or even.
Answers
Answered by
2
1) using if_else
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter an integer: ";
cin >> n;
if ( n % 2 == 0)
cout << n << " is even.";
else
cout << n << " is odd.";
return 0;
}
2) using ternary operators
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter an integer: ";
cin >> n;
(n % 2 == 0) ? cout << n << " is even." : cout << n << " is odd.";
return 0;
}
Answered by
1
#include <iostream>
using namespace std;
int main()
{
int i, number;
for(i = 1; i <= 10; i++)
{
cin >> number;
if(number % 2 == 0)
cout << "Even" << endl;
else
cout << "Odd" << endl;
}
return 0;
}
Hope this helps! :)
AccioNerd:
IF IT HELPS THEN PLEASE MARK AS BRAINLIEST!
Similar questions