0
Plz tell me how divison works in c++......how 13/7 comes out to be 1........13/7=1
5 Answers
+ 5
The compiler reads the integer data type , divides it and drops the remainder. You need to use float to get decimal values
+ 1
like in real world, if you use integers then 13/7=1
13 days /7 = 1 week (+6 days)
+ 1
/ when used with integers is the euclidian division (you can also get the remainder with the % operator). If you want the normal division, at least one of the operand has to be a float or double. You may want to do a cast for that.
cout << 13.0/7.0;
int a = 13, b = 7;
cout << (double)a/b;
0
it works like that because you declared an integer... try using float or double... integer is a whole number... it'll give you the whole number and displace the decimal
- 1
use 'float' data type instead of 'int'