Why ans 0 in %d and not 10? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why ans 0 in %d and not 10?

#include <stdio.h> int main() { float average; int total = 7; int count = 2; float he = 3.5; average = total / count*he; printf("%d and %f", average, average ); return 0; } //why ans 0 in %d and 10.500000 in %f https://code.sololearn.com/ccLMAC9JGh3f/?ref=app

10th Jun 2019, 4:30 PM
Avi Tiwari
Avi Tiwari - avatar
5 Answers
+ 3
Normally, when you work with floats and ints, the compiler does conversions automatically. However, with printf, the compiler does not know what type the function expects, so it leaves it as a float, when it should be an integer. To solve this, you have to explicitly convert it to an int.
10th Jun 2019, 4:56 PM
Vlad Serbu
Vlad Serbu - avatar
+ 2
Because the first parameter expects explicit type conversion integer to float 🤔
12th Jun 2019, 3:00 AM
Sanjay Kamath
Sanjay Kamath - avatar
0
Because printf expects an integer, but you give it a float. https://code.sololearn.com/cZk8Bd9oPFvP/?ref=app
10th Jun 2019, 4:47 PM
Vlad Serbu
Vlad Serbu - avatar
0
Vlad Serbu can you elaborate I can't understand you.
10th Jun 2019, 4:49 PM
Avi Tiwari
Avi Tiwari - avatar
0
Panpan quququ pananabanana yo to yo eh
19th Jul 2019, 10:55 AM
Ilyes AICHOUCH
Ilyes AICHOUCH - avatar