Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //нерекурсивная функция
- #include <iostream>
- using namespace std;
- int gcd (int a, int b)
- {
- int x = a, y = b, r;
- while (y)
- {
- r = x % y;
- x = y;
- y = r;
- }
- return x;
- }
- int main()
- {
- int a, b, c, d;
- cout << "Введите числа a, b, c, d:\n";
- cin >> a >> b >> c >> d;
- cout << "a/b + d/c = " << (a*c + b*d) / gcd(a*c + b*d, b*c) << "/" << b*c / gcd(a*c + b*d, b*c);
- return 0;
- }
- //рекурсивная функция
- #include <iostream>
- using namespace std;
- int gcd (int a, int b)
- { if (b) gcd(b, a % b); else return a; }
- int main()
- {
- int a, b, c, d;
- cout << "Введите числа a, b, c, d:\n";
- cin >> a >> b >> c >> d;
- cout << "a/b + d/c = " << (a*c + b*d) / gcd(a*c + b*d, b*c) << "/" << b*c / gcd(a*c + b*d, b*c);
- return 0;
- }
Add Comment
Please, Sign In to add comment