Redesign program in exercise 1 for sheet#7 part1 to use only void functions and
ID: 3547073 • Letter: R
Question
Redesign program in exercise 1 for sheet#7 part1 to use only void functions and Call-by-Reference. You should not use any global variables in your program.
exercise 1 for sheet#7 part1 :
*Exercise 1:
Write a function multiple that determines for a pair of integers whether the second integer is a multiple of the first. The function should take two integer arguments and return true if the second is a multiple of the first, false otherwise. Use this function in a program that inputs a series of pairs of integers.
. Example: If input is 256 and 8, output will be 256 is a multiple of 8
If input is 13 and 111, output will be 111 is not, a multiple of 13.
Explanation / Answer
#include <iostream>
using namespace std;
bool isMultiple( int a, int b ) //to check if b is a multiple of a
{
if(a%b == 0 )
return true;
else
return false;
}
int main() {
int a,b;
cin >> a >> b;
if (isMultiple(a,b)){
cout << a << " is a multiple of " << b << endl;
}
else cout << a << " is not, a multiple of " << b << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.