if p and q are two rational nmbr and i m adding these nmbrs | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

if p and q are two rational nmbr and i m adding these nmbrs

then what this statements denotes? Rational r=(Rational) n; int p=this.p*r.q+this.q*r.p; int q= this.q*r.q; return new rational(p,q); plz tell me the complete description of it..!

9th Feb 2017, 6:00 AM
Pooja Upadhyay
Pooja Upadhyay - avatar
2 Answers
+ 3
Your code seems to use a class Rational ( in the 5th line, didn't you need a 'R' capitalized? ), which as two properties 'p' and 'q' where: Rational r = new Rational(p,q); // r = p/q Guessing that yur code sample go in a method of the class Rational, the code calculate the sum of the actual/current ( this ) Rational object with another ( 'r' in your example ), and return a new Rational(P,Q) where: P = this.p * r.q and Q = this.q * r.q ... because: ( a/b ) + ( c/d ) <=> ( ( a*d ) / ( b*d ) ) + ( ( c*b ) / ( b*d ) ) <=> ( a*d + c*b ) / ( b*d )
9th Feb 2017, 10:41 AM
visph
visph - avatar
0
hmmm..thanks :)
9th Feb 2017, 10:44 AM
Pooja Upadhyay
Pooja Upadhyay - avatar