Ask Question
3 October, 07:20

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

using only. C+ + programming

+4
Answers (1)
  1. 3 October, 07:25
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers