0

Is this the correct way to use the ceil function here?

#include <stdio.h> #include <math.h> int main() { int houses; scanf("%d", &houses); double percentage; percentage=(100*2)/houses; int result= ceil(percentage); printf("%d\n",result); return 0; } If not, please correct the code..

26th Apr 2020, 5:47 PM
Ashfaq Reshad
Ashfaq Reshad - avatar
2 Respostas
+ 1
Instead of 100 * 2, make it 200, but don't forget .0 I mean it should be 200.0 / houses Otherwise, when it is 200 / houses it will always return integer, because compiler will think you are dividing int by int.
26th Apr 2020, 5:55 PM
Mustafa K.
Mustafa K. - avatar
0
Mustafa, Thank you❤
26th Apr 2020, 6:01 PM
Ashfaq Reshad
Ashfaq Reshad - avatar