Computer Science, asked by sam22006, 1 year ago

write a program in c++ to enter 10 no. and print whether which no is odd or even.​

Answers

Answered by misnaminglover
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 AccioNerd
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