Question:
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.)
Answer:
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
cout << "Enter two integers: ";
cin >> num1 >> num2;
if ( num1 % num2 == 0 )
cout << num1 << " is a multiple of " << num2 << endl;
if ( num1 % num2 != 0 )
cout << num1 << " is not a multiple of " << num2 << endl;
return 0;
}
No comments:
Post a Comment