Aodai

Untitled

Mar 2nd, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using std::cout;
  3. using std::cin;
  4. using std::endl;
  5.  
  6. struct Rational
  7. {
  8.     int m_numerator;
  9.     int m_denominator;
  10.  
  11. };
  12.  
  13. Rational sum(Rational n1, Rational n2)
  14. {
  15.     Rational result = { (n1.m_numerator * n2.m_denominator) + (n1.m_denominator * n2.m_numerator), n1.m_denominator * n2.m_denominator };
  16.     return result;
  17. }
  18.  
  19. int main()
  20. {
  21.     Rational num1 = {6, 12}, num2 = {5, 10};
  22.     Rational result = sum(num1, num2);
  23.     cout << "Sum is " << result.m_numerator << "/" << result.m_denominator << endl;
  24.     system("pause");
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment