0

fraction operations

Requirement Enough computer science today, let's do a little math. Imagine entering 4 natural numbers x, y, z and w from the keyboard. The variables x and y are the numerator, respectively the denominator of a fraction F1. Also with z and w I wrote down the numerator and denominator of the other fraction F2. Calculate the sum and product of the fractions F1 and F2, bringing them to the irreducible form. Input data The 4 numbers x, y, z and w described above are read from the keyboard. Output data The following variables a, b, c, and d will be displayed on the screen. Restrictions and specifications 0 <x, y, z if w <1,000 Example Input data Output data 60 40 36 80 39 20 27 40 this I tried but not work ,some advice please? #include <iostream> using namespace std; int main(){ int x,y,z,w,a,b,c,d,r1,r2; cin>>x>>y>>z>>w; a=x*y+z*y; b=y*w; c=x*y; d=y*w; while(b!=0){ r1=a%b; a=b; b=a; } int gcd=b; while(d!=0){ r2=d%c; d=c; c=d; } int gcd2 =d; a/=gcd; b/=gcd; c/=gcd2; d/=gcd2; cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl; return 0; }

11th Apr 2021, 4:48 PM
Andrei Macovei
Andrei Macovei - avatar
2 Respostas
0
Btw these while loops both look like infinite loops
11th Apr 2021, 10:29 PM
Michal Doruch
0
and how I should do it?
12th Apr 2021, 5:38 AM
Andrei Macovei
Andrei Macovei - avatar