forked from Rustam-Z/cpp-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcd.cpp
More file actions
20 lines (20 loc) · 716 Bytes
/
Copy pathgcd.cpp
File metadata and controls
20 lines (20 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
int gcd(int x, int y) {
if (x == 0 || y==0)
return y,x;//will input non-zero number when even one number inputed in zero
if (x == y)
return x;//will return first number when both of the numbers are equal
if (x > y)
return gcd(x - y, y);//when first number is greater than second
if( y > x )
return gcd(x, y - x);//when second number is greater than first
}
int main4() {
cout << "\t\t\t***Program to calculate the G.C.D for two integers usin recurion.***" << endl;
cout << "Please enter two integers: " << endl;
int x,y;
cin >> x >> y;
cout << "The G.C.D of " << x << "and " << y << " is " << gcd(x, y);//calling function in the main function
return 0;
}