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..!
2 Respostas
+ 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 )
0
hmmm..thanks :)