Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <typeinfo>
- #include <cmath>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "Rus");
- bool isNotCorrect = false;
- int multiFirst, multiSecond, c ,aFirst, bFirst, numFirst, numSecond, denomFirst, denomSecond;
- do {
- cout << "Введите числитель 1 дроби\n";
- cin >> numFirst;
- if (cin.fail()) {
- isNotCorrect = true;
- cout << "Данные ввеены неккоректно" << endl << endl;
- cin.clear();
- while (cin.get() != '\n');
- }
- else {
- isNotCorrect = false;
- }
- } while (isNotCorrect);
- do {
- cout << "Введите числитель 2 дроби\n";
- cin >> numSecond;
- if (cin.fail()) {
- isNotCorrect = true;
- cout << "Данные ввеены неккоректно" << endl << endl;
- cin.clear();
- while (cin.get() != '\n');
- }
- else {
- isNotCorrect = false;
- }
- } while (isNotCorrect);
- do {
- cout << "Введите знаменатель 1 дроби\n";
- cin >> denomFirst;
- if (cin.fail()) {
- isNotCorrect = true;
- cout << "Данные ввеены неккоректно" << endl << endl;
- cin.clear();
- while (cin.get() != '\n');
- }
- else {
- isNotCorrect = false;
- }
- } while (isNotCorrect);
- do {
- cout << "Введите знаменатель 2 дроби\n";
- cin >> denomSecond;
- if (cin.fail()) {
- isNotCorrect = true;
- cout << "Данные ввеены неккоректно" << endl << endl;
- cin.clear();
- while (cin.get() != '\n');
- }
- else {
- isNotCorrect = false;
- }
- } while (isNotCorrect);
- multiFirst = numFirst * numSecond;
- multiSecond = denomFirst * denomSecond;
- if (multiSecond == 0) {
- cout << "Нуль знаменатель!\n ";
- }
- if (multiFirst == 0) {
- cout << multiFirst << "/" << multiSecond << "=0\n";
- }
- aFirst = multiFirst;
- bFirst = multiSecond;
- if (multiSecond > multiFirst) {
- c = multiFirst;
- multiFirst = multiSecond;
- multiSecond = c;
- }
- while (multiFirst % multiSecond != 0) {
- c = multiSecond;
- multiSecond = multiFirst % multiSecond;
- multiFirst = c;
- }
- cout << aFirst << "/" << bFirst << "=" << aFirst / multiSecond;
- if (bFirst / multiSecond != 1) {
- cout << "/" << bFirst / multiSecond << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement