Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int gcd1(int y, int z)
- {
- if (z == 0)
- {
- return y;
- }
- else if (y == 0)
- {
- return z;
- }
- else
- {
- return gcd1(z, y % z);
- }
- }
- int gcd(int x, int y, int z)
- {
- if (x == 0)
- {
- return x;
- }
- else if (z == 0)
- {
- return y;
- }
- else if (y == 0)
- {
- return z;
- }
- else
- {
- return gcd(y, x%y,gcd1(y,z));
- }
- }
- int main()
- {
- //values for x,y,z
- int x, y, z;
- cin >> x; cin >> y; cin >> z;
- if (x < 20 || x > 300 || y < 20 || y > 300 || z < 20 || z > 300)
- {
- cout << "Invalid input data!";
- return 1;
- }
- cout << gcd(x, y, z);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement