Advertisement
edutedu

simplificare fractii cu functii in structura

Oct 15th, 2020
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct fractie {
  6. int nu;
  7. int nr;
  8. }f1,f2,f3;
  9.  
  10. int cmmdc(int a, int b)
  11. {
  12. if(a!=0 && b!=0)
  13. {
  14. while(a!=b)
  15. {
  16. if(a>b)
  17. a-=b;
  18. else
  19. b-=a;
  20. }
  21. return a;
  22. }
  23. else
  24. {
  25. return 1;
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. float rez;
  32. cin>>f1.nr>>f1.nu;
  33. cin>>f2.nr>>f2.nu;
  34. int c=cmmdc(f1.nu,f1.nr);
  35. f1.nu=f1.nu/c;
  36. f1.nr=f1.nr/c;
  37. c=cmmdc(f2.nu,f2.nr);
  38. f2.nu=f2.nu/c;
  39. f2.nr=f2.nr/c;
  40. cout<<f1.nr<<"/"<<f1.nu<<endl;
  41. cout<<f2.nr<<"/"<<f2.nu<<endl;
  42.  
  43. if((1.0*f1.nr)/f1.nu > (1.0*f2.nr)/f2.nu)
  44. cout<<f1.nr<<"/"<<f1.nu<<endl;
  45. else
  46. cout<<f2.nr<<"/"<<f2.nu<<endl;
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement