{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Problem Exercises Chapter 01

# Problem Exercises Chapter 01 - 1 Page 56 Exercise 31 Write...

This preview shows pages 1–3. Sign up to view the full content.

1. Page 56: Exercise 31. Write a program that reads an integer and determines and prints whether it is odd or even. (Hint: Use the modulus operator. An even number is a multiple of two. Any multiple of two leaves a remainder of zero when divided by 2.) #include <iostream> using std::cout; using std::endl; using std::cin; int main() { int num; // declare variable cout << "Enter a number: "; // prompt user cin >> num; // read value from keyboard if ( (num % 2) == 0 ) // If " num " is even, then cout << "The number " << num << " is even." << endl; if ( (num % 2) != 0 ) // If " num " is odd, then cout << "The number " << num << " is odd." << endl; return 0; //indicate successful termination } A sample screen output look like :

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2. Page 56: Exercise 32. Write a program that reads in two integers and determines and prints if the first is a multiple of the second. (Hint: Use the modulus operator.) #include <iostream> using std::cout; using std::endl; using std::cin; int main() { int num1, num2;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

Problem Exercises Chapter 01 - 1 Page 56 Exercise 31 Write...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online