+ 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?
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;
}
+ 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.
+ 1
Oh that makes sense, thanks for the explaining, now i get it. :)
0
why did you put 200.0 instead of 200?
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?