0

Why am I getting 0 as the output? Shouldn't the output be 40?

#include <studio.h> int main() { int volume; int length = 5; int width = 8; volume = length * width; printf("%f", volume); return 0; }

9th Mar 2018, 4:39 PM
Atiq Rahman
Atiq Rahman - avatar
6 Réponses
+ 3
printf("%d \n", volume); /* 40 */
9th Mar 2018, 5:16 PM
Aidos Zhakupov
Aidos Zhakupov - avatar
+ 2
can only be used: d decimal c character s string f float e scientific notation x hexadecimal
9th Mar 2018, 5:24 PM
Aidos Zhakupov
Aidos Zhakupov - avatar
+ 1
%f for digits with floating point. You have integer type variables. At the output you send to the console the value in the floating point. Therefore, it turns out 0.000
9th Mar 2018, 5:18 PM
Aidos Zhakupov
Aidos Zhakupov - avatar
0
Then you show me the right approach.
9th Mar 2018, 5:13 PM
Atiq Rahman
Atiq Rahman - avatar
0
Won't printf("%i, volume); would do the work? @Aidos
9th Mar 2018, 5:20 PM
Atiq Rahman
Atiq Rahman - avatar
0
it would if you quote close the %i printf("%i ", volume);
9th Mar 2018, 10:05 PM
Otumian Empire
Otumian Empire - avatar