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
Write a program to print random numbers and whether they were even or odd. Ask the...
Write a program to print random numbers and whether they were even or odd. Ask the user to enter a positive number to indicate how many random numbers to pull (verify number is positive). Zero is positive. Declare two variables and initialized to zero. int evens = 0, odds = 0; Use them to count how many evens and how many odds were pulled. Enter how many random numbers to pull : 3 41           odd 18467    odd 6334    even 1...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT