Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define N 301
- using namespace std;
- ifstream fin("date.in");
- ofstream fout("date.out");
- struct fractie
- {
- int x,y;///date membre
- ///metode
- void citire()
- {
- fin>>x>>y;
- }
- void afisare()
- {
- fout<<x<<"/"<<y<<"\n";
- }
- void ireductibil()
- {
- int r,a,b;
- a=x;
- b=y;
- while(b!=0)
- {
- r=a%b;
- a=b;
- b=r;
- }
- x/=a;
- y/=a;
- }
- };
- fractie suma(fractie f1, fractie f2)
- {
- fractie f;
- f.x=f1.x*f2.y+f1.y*f2.x;
- f.y=f1.y*f2.y;
- f.ireductibil();
- return f;
- }
- int main()
- {
- fractie f1, f2, fs;
- f1.citire();
- f1.afisare();
- f1.ireductibil();
- f1.afisare();
- f2.citire();
- f2.afisare();
- fs=suma(f1,f2);
- fs.afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment