25. Program that reads in two integers and determines and prints if the first is a multiple of the second.

C++ How to Program (8th Edition)

Chapter 2

Introduction to C++ Programming

Exercise

25. 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::cin;
using std::endl;
int main()
{
 int num1, num2;
 cout<<"Enter two integers:";
 cin>>num1>>num2;
 
 if(num1%num2==0)
 cout<<num1<<" is a multiple of the "<<num2<<endl;
 
 if(num1%num2!=0)
 cout<<num1<<" is not a multiple of the "<<num2<<endl;
 
 return 0;
}

Let me know in the comment section if you have any question.

Similar Posts:

Chapter 2

  1. Program that asks the user to enter two numbers, obtains the two numbers from the user and prints the sum, product, difference, and quotient of the two numbers.
  2. Program that prints the numbers 1 to 4 on the same line with each pair of adjacent numbers separated by one space.
  3. Program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words "is larger." If the numbers are equal, print the message "These numbers are equal."
  4. Program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers.
  5. Program that reads in the radius of a circle as an integer and prints the circle’s diameter, circumference and area.Use the constant value 3.14159 for π. Do all calculations in output statements.
  6. Program that prints a box, an oval, an arrow and a diamond.
  7. Program that reads in five integers and determines and prints the largest and the smallest integers in the group.
  8. Program that reads an integer and determines and prints whether it’s odd or even.
  9. Program that reads in two integers and determines and prints if the first is a multiple of the second.
  10. Display checkerboard pattern with eight output statements, then display the same pattern using as few statements as possible.
  11. Program that prints the integer equivalent of a character typed at the keyboard.
  12. Program that inputs a five-digit integer, separates the integer into its digits and prints them separated by three spaces each.
  13. Program that calculates the squares and cubes of the integers from 0 to 10.

 Chapter 3: 

Comments