write a program to find gcd of 4 number using recursion
Answers
Answered by
1
#include<iostream>
using namespace std;
int gcdx(int a, int b) {
if (a == 0 || b == 0)
return 0;
else if (a == b)
return a;
else if (a > b)
return gcdx(a-b, b);
else
return gcdx(a, b-a);
}
int gcdfour(int a, int b, int c, int d){
return gcdx(gcdx(a,b),gcdx(c,d));
}
int main() {
int a = 1, b = 2, c = 3, d = 4; // replace the values with your own
cout << gcdfour(a,b,c,d) << endl;
return 0;
}
//this is all in c++
Similar questions
Chemistry,
1 month ago
Math,
1 month ago
Social Sciences,
1 month ago
Math,
10 months ago
Chemistry,
10 months ago
Computer Science,
10 months ago