petrusenik

Untitled

Oct 28th, 2023
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int gcd(int a, int b) {
  4.     while (b != 0) {
  5.         int temp = b;
  6.         b = a % b;
  7.         a = temp;
  8.     }
  9.     return a;
  10. }
  11.  
  12. int main() {
  13.     int numerator, denominator;
  14.     std::cout << "Въведете числител и знаменател: ";
  15.     std::cin >> numerator >> denominator;
  16.  
  17.     int common_divisor = gcd(numerator, denominator);
  18.  
  19.     int reduced_numerator = numerator / common_divisor;
  20.     int reduced_denominator = denominator / common_divisor;
  21.  
  22.     std::cout << "Изход: " << reduced_numerator << " " << reduced_denominator << std::endl;
  23.  
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment