nicuvlad76

Untitled

Dec 8th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define N 301
  3. using namespace std;
  4. ifstream fin("date.in");
  5. ofstream fout("date.out");
  6. struct fractie
  7. {
  8. int x,y;///date membre
  9. ///metode
  10. void citire()
  11. {
  12. fin>>x>>y;
  13. }
  14. void afisare()
  15. {
  16. fout<<x<<"/"<<y<<"\n";
  17. }
  18. void ireductibil()
  19. {
  20. int r,a,b;
  21. a=x;
  22. b=y;
  23. while(b!=0)
  24. {
  25. r=a%b;
  26. a=b;
  27. b=r;
  28. }
  29. x/=a;
  30. y/=a;
  31. }
  32. };
  33.  
  34. fractie suma(fractie f1, fractie f2)
  35. {
  36. fractie f;
  37. f.x=f1.x*f2.y+f1.y*f2.x;
  38. f.y=f1.y*f2.y;
  39. f.ireductibil();
  40. return f;
  41. }
  42. int main()
  43. {
  44. fractie f1, f2, fs;
  45. f1.citire();
  46. f1.afisare();
  47. f1.ireductibil();
  48. f1.afisare();
  49. f2.citire();
  50. f2.afisare();
  51. fs=suma(f1,f2);
  52. fs.afisare();
  53. return 0;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment