0

Plz tell me how divison works in c++......how 13/7 comes out to be 1........13/7=1

16th Oct 2016, 11:34 AM
M Ans CH
M Ans CH - avatar
5 odpowiedzi
+ 5
The compiler reads the integer data type , divides it and drops the remainder. You need to use float to get decimal values
16th Oct 2016, 3:29 PM
StillSoul‌‌‌‌‌‌‌‌‌‌‌‌‌‍
StillSoul‌‌‌‌‌‌‌‌‌‌‌‌‌‍ - avatar
+ 1
like in real world, if you use integers then 13/7=1 13 days /7 = 1 week (+6 days)
16th Oct 2016, 11:57 AM
marcram
+ 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;
16th Oct 2016, 12:18 PM
Zen
Zen - avatar
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
12th Dec 2016, 6:16 PM
ABDULJABBAR
ABDULJABBAR - avatar
- 1
use 'float' data type instead of 'int'
16th Oct 2016, 11:36 AM
Dhruv Bothra
Dhruv Bothra - avatar