Type conversion confusion | SoloLearn: Learn to code for FREE!

+1

Type conversion confusion

Look at the comented text below : #include <stdio.h> int main() { float average; int total = 23; int count = 4; #in this code. when we are not using float its output get change to 5.00 . Why...???? average = (float)total / count; printf("%4.2f", average); return 0; }

6/1/2020 5:57:39 AM

Anjali Singh

3 Answers

New Answer

+3

Oo.. ok. Thanks, i got it..😊

+2

This is because both numerator and denominator are integers. So integer divison is performed i.e any fractional part is thrown away. Then since the average variable is of type float, int is converted to float

0

Go through this...might help #include <stdio.h> int main() { float average; int total = 23; int count = 4; #in this code. when we are not using float its output get change to 5.00 . Why...???? average = (float)total / count; printf("%4.2f", average); return 0; }