Halloween candy codecoach! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Halloween candy codecoach!

#include <stdio.h> #include<math.h> int main() { int houses; scanf("%d", &houses); float b=(200.0/houses); printf("%.0f",ceil(b)); //your code goes here return 0; } Is there any other ways to do it?

24th Dec 2019, 5:32 PM
Geek
Geek - avatar
4 Answers
+ 3
#include <stdio.h> int main() { int houses; scanf("%d", &houses); int perc = (int)(((2.0/(double)houses)*100.0) + 0.99); printf("%d", perc); return 0; }
25th Dec 2019, 12:23 AM
Mark
+ 2
Hi Dan Delgado If 200 were to be used, the result would be the integer part of the division 200/houses, as both terms are integer. But using 200.0 the compiler automatically cast the division as a floating point operation.
6th May 2020, 12:03 PM
Mark
+ 1
Oh that makes sense, thanks for the explaining, now i get it. :)
9th May 2020, 1:56 PM
Dan Delgado
Dan Delgado - avatar
0
why did you put 200.0 instead of 200?
26th Apr 2020, 7:28 PM
Dan Delgado
Dan Delgado - avatar