| |
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? |
| April 04, 2009 14:07:37 |
#10 |
| iantuy |
Member Since: October 2008 Total Comments: 2 |
RE: Fix Function |
#include<stdio.h> int fix(float a) { return a>=0?a:(float)(int)a-a?a-1:a; } int main() { printf("%d %d %d",fix(2.5f),fix(-2.1),fix(-2.0f)); return 1; } |
| |
Back To Question | |