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...
//----------------------------------------------------------------- // Counts the number of odd, even, and zero digits in an integer // input value. Repeat as long as the user wishes to continue //----------------------------------------------------------------- public static void main(String[] args) {     // Declare the identifiers final int SENTINEL = -99;    // Declare the remaining identifiers ... Scanner scan = new Scanner(System.in);    // Display the programmer's information              // Input an integer number          // Count the number of odd, even, and...
Create an application that checks whether an integer is an odd or even number. Welcome to...
Create an application that checks whether an integer is an odd or even number. Welcome to the Odd/Even Checker! Enter an integer: ten Error! Invalid integer. Try again. Enter an integer: 10.3 Error! Invalid integer. Try again. Enter an integer: 10 The number 10 is even. Continue? (y/n): Error! This entry is required. Try again. Continue? (y/n): y Enter an integer: 9 The number 9 is odd. Continue? (y/n): n Specifications: Create a version of the Console class presented in...
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
True or False: It's easy to loop through an array using a for loop in C++...
True or False: It's easy to loop through an array using a for loop in C++ because you can use the .size() function to get the total number of spaces in the array True or False: It's easy to loop through a vector using a for loop in C++ because you can use the .size() function to get the total number of spaces in the vector
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
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.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT