Problem Exercises Chapter 01

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

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

View Full Document Right Arrow Icon
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 :
Background image of page 1

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

View Full DocumentRight Arrow Icon
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;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online