Question

In: Computer Science

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

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

using only <iostream> . C++ programming

Solutions

Expert Solution

#include <iostream>
using namespace std;
  
// It will return true if n is even. Otherwise odd.
bool isEven(int n)
{
bool isEven = true;
   if(n<0)
n=-n;
for (int i=1; i<=n; i++)
   isEven = !isEven;
return isEven;
}
  
int main()
{
int n;
   cout<<" Enter an integer:";
   cin>>n;
isEven(n) ? cout << "Even" : cout << "Odd";
return 0;
}

Output:


Related Solutions

Counts the number of odd, even, and zero digits in an integer input value. Repeat until...
Counts the number of odd, even, and zero digits in an integer input value. Repeat until user does not want to continue. Develop the program in an incremental fashion. For example, write the part of the program, which inputs a single integer value and displays number of odd, even, and zero digits in that number. Submit your partial program for grading to make sure it works for the first few test cases. Below is an example execution of a partial...
prove that if an even integer n is subtracted from an odd integer m. then m...
prove that if an even integer n is subtracted from an odd integer m. then m - n is odd.
prove that every integer is either even or odd but never both.
prove that every integer is either even or odd but never both.
Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number....
Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number. The main function is given: int main(){     int number;     cout << "Check number input: ";     cin >> number;     cout << "The input number " << number << " is " << checkEvenOrOdd(number) << endl;     return 0; } simple c++ code please
How to write a java application that reads an integer, then determines and display whether it's...
How to write a java application that reads an integer, then determines and display whether it's odd or even. Use the remainder operator.
determine whether the given function is even, odd, or neither. Please write a code in MatLab...
determine whether the given function is even, odd, or neither. Please write a code in MatLab to solve this problem below: 1.f(x) = sin 3x please only use Matlab to solve this problem
Sum the odd integers between 1 and 99 using a for structure. Assume the integer variables...
Sum the odd integers between 1 and 99 using a for structure. Assume the integer variables sum and count have been declared. Calculate the value of 2.5 raised to the power of 3 using pow method. Print the integers from 1 to 20 using a while loop and the counter variable x. Assume that the variable x has been declared but not initialized. Print only five integers per line.[ Hint: Use calculation x % 5. When the value of this...
Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
There should be a half-line difference between odd and even fields in a TV system using...
There should be a half-line difference between odd and even fields in a TV system using interlaced scanning. Explain why? How is this made possible in practice?
create a program using IDLE where you will gather input from the user using a loop....
create a program using IDLE where you will gather input from the user using a loop. The user needs to provide you with a list of test scores for two categories (two different classrooms). Test scores must be integer values between 0 and 10. You need to process each score so that you can output the following: Number of test scores entered for classroom A. Number of test scores entered for classroom B. Average of test scores entered for classroom...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT