| |
GeekInterview.com > Interview Questions > Programming > C
| Print | |
Question: Fix Function
Answer: Write the implementation of Fix function? fix(2.5) = 2 and fix(-2.25) = -3, this is the expected result. Write the code to implement this behaviour? |
| March 03, 2009 03:48:20 |
#5 |
| vbablu |
Member Since: February 2009 Total Comments: 4 |
RE: Fix Function |
void fix(float); void main() { float f; scanf("%",&f); fix(f); getch(); } void fix(float f) { float x; if(f<0) { x=f-(int)f; f=f-x; printf("%d",(int)f); } else if(f<0) { x=f-(int)f; f=f-x-1; printf("%d",(int)f); } } |
| |
Back To Question | |