Ask Question
8 October, 13:38

Using for loop. Input an integer and identify whether it's EVEN OR ODD (without using modulo operator)

using only. C+ + programming

+5
Answers (1)
  1. 8 October, 16:39
    0
    Following are the program in c+ + language

    #include / / header file

    using namespace std; / / namespace

    int main ()

    {

    int n1, i; / / variable declaration

    cout<<"Enter Number: ";

    cin>>n1; / / input number

    for (i=n1; i>1; i=i-2) / / check the condition

    {

    n1 = n1-2; / / decrement the value of number by - 2

    }

    if (n1==0) / / check if it is 0

    cout<<"number is EVEN"<<"/n"; / / print even

    else

    cout<<"number is ODD"<<"/n"; / / print odd

    return 0;

    }

    Output:

    Enter Number: 45

    number is ODD

    Again run the program

    Enter Number:10

    number is EVEN

    Explanation:

    In this program, we input the number by a user in variable n1. After that, we iterate the for loop and initialize the value of a variable" i" in for loop and check the condition.

    In each iteration, the variable n1 is decrement by 2 and store it n1.

    Finally, check if n1==0 then it print number is EVEN otherwise it print number is ODD.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Using for loop. Input an integer and identify whether it's EVEN OR ODD (without using modulo operator) using only. C+ + programming ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers