State two ways to compute the approximate numerical value of the quotient a/b if a and b are both integer variables in a C++ program. (b !=0)
one way is certainly a=a/b;
What do u think is the other way???
maybe be using reference ? or other tricky way?
C++ challenging quetion about quotient?
c=0;
while (b%26gt;=a)
{
b=b-a;
c++;
}
cout%26lt;%26lt;c;
given b is the divident and a is the divisor, c is the quotient
Reply:you wana divide two integers ,
int a,b;
// short ways is below
a/=b;
// will be a = a/b ;
hey, your question is also confusing , you have not decalred what you want (exactly ) . . .
WELL JOHN , A CHANGE IN YOUR MIND WASN"T GOOD IDEA . . . all the best with your programming and make sure you don't mess up with the variable in your real program instead of c you use a ;-)
joking,
all the best
a l the best
Reply:%26gt;%26gt;one way is certainly a=a/b;
I don't think so.
If a=7 and b=3, then a/b will give you 2, not 2.3333 as you were expecting. That's because both are integers and
int / int will give you an int.
You will have to cast at least one of those integers to float like this:
(static_cast%26lt;float%26gt;a) / b;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment