+ 1

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
5 Respuestas
+ 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
+ 3
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
0
I thought alike and I still don't understand why it's wrong. Follows below my code: #include <stdio.h> int main() { int houses; scanf("%d", &houses); //your code goes here float prob = 200 / houses; printf("%.0f",prob); return 0; } Since I declared 'prob' as float and used '%.0f' on printf() shouldn't it round prob to the nearest whole number?
23rd Dec 2024, 1:17 AM
Guilherme Rodrigues
Guilherme Rodrigues - avatar