In: Computer Science
c++
Write a program that will ask the user for three pairs of integer values. The program will then display whether the first number of the pair is multiple of the second.
The actual work of making the determination will be performed by a function called IsMultiple that takes two integer arguments (say, x and y). The function will return a Boolean result of whether x is a multiple of y.
In this C++ program,
- In main, we are prompting the user to enter pairs of integer
values, then
- We are calling the function isMultiple which will take 2
arguments and return a boolean value.This function will check if
the first number of the pair is multiple of the second then returns
true if satisfied else return false.
- Again back in main, we are storing the result, and printing
whether the first number is a multiple of the second number or
not,
(I believe that I made the code simple and understandable. If you still have any query, Feel free to drop me a comment)
Code:
#include <iostream>
using namespace std;
//This function will take 2 arguments and return a boolean
value
bool isMultiple(int x,int y)
{
if(x%y==0)
return true;
else
return false;
}
int main()
{
int a,b;//Declared this variables to store integer pairs
//Looping to accept 3 pairs of integer values
for(int i=0;i<3;i++)
{
//Prompting and reading the values from the user
cout<<"Enter the Integer pair "<<i+1<<": ";
cin>>a>>b;
//Calling the function and storing the result
bool result=isMultiple(a,b);
//Printing whether it is a muliple or not
if(result)
cout<<a<<" is a muliple of "<<b;
else
cout<<a<<" is not a muliple of "<<b;
cout<<endl;
}
return 0;
}
Output:
Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...