2015年9月23日 星期三

Two floating numbers 四捨五入


Input two floating numbers X and P.

a. 0 < X <1
b. P = 1 / 0.1 / 0.01/ 0.001
c. answer format %.4f

ex:
if X is 0.5678 and P is 0.01, then the answer is 0.5700
if X is 0.1269 and P is 0.1, then the answer is 0.1000



#include <stdio.h>

int main(void) {

float x, p;
while(EOF != scanf("%f %f", &x, &p)) {

if (0 < x && x < 1) {

x = (int)(x*(1/p) + 0.5);
printf("%0.4f\n", x/(1/p));
}
}
return 0;
}

沒有留言:

張貼留言