Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int inputVariables() {
- int name;
- cin >> name;
- return name;
- }
- int FindNumerator(int m, int n, int p, int q) {
- int a;
- a = ((m * q) + (p * n));
- return a;
- }
- int FindDenumerator(int n, int q) {
- int b = 0;
- b = n * q;
- return b;
- }
- int ReduceFunction(int c, int d, int x) {
- do {
- if (c > d) {
- c = (c - d);
- }
- else
- d = (d - c);
- } while (c != d);
- if (x == 1) {
- return c;
- }
- if (x == 2) {
- return d;
- }
- return ;
- }
- static void PrintFraction(int a, int b, int c, int d) {
- cout << (a / c) << "/" << (b / d);
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- cout << "Данная программа находит сумму двух несократимых дробей." << endl;
- cout << "Введите дроби" << endl;
- int m = inputVariables();
- int n = inputVariables();
- int p = inputVariables();
- int q = inputVariables();
- int a = FindNumerator(m, n, p, q);
- int b = FindDenumerator(n, q);
- int c = a;
- int d = b;
- c = ReduceFunction(c, d, 1);
- d = ReduceFunction(c, d, 2);
- cout << "Сумма равна:" << endl;
- PrintFraction(a, b, c, d);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement