76 311
Assignments Done
98,1%
Successfully Done
In May 2019

Answer to Question #48156 in C++ for joney

Question #48156
1- Write a function that receives two integers if both are zeros return one otherwise return zero
2- Write a function that will receives the two integers from the main and return the greatest common divisor.


In the void main do the following:void main(){}
-Keeps reading two integers and find their largest common divisor until the user enters ( 0 , 0 )
- You should use the first function to check if the user enters (0,0) so you will stop reading.
- You should use the second function to find the largest common divisor.
-Result of the largest common divisor should be displayed on screen
Expert's answer
#include <iostream>
using namespace std;
int func1 ( int a, int b ) {
if ( (0 == a) && ( 0 == b ) ) {
return 1;
}
return 0;
}
int gcd ( int a, int b ) {
int c;
while ( a != 0 ) {
c = a;
a = b % a;
b = c;
}
return b;
}
int main() {
cout << func1(0, 1)
<< func1(0, 0)
<< func1(1, 1)
<< func1(1, 0)
<< endl;
cout << "gcd( 15, 54 ) = "
<< gcd( 15, 54 )
<< endl;
return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions