| |
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 03:40:45 |
#9 |
| ashu_1988 |
Member Since: April 2009 Total Comments: 1 |
RE: Fix Function |
#include<stdio.h> #include<conio.h> main() { int flr(float); clrscr(); printf("the value of 2.5=%dnthe value of -2.25=%d",flr(2.5),flr(-2.25)); getch(); } int flr(float n) { int p; p=n; if(n-p) { if(p<0) return(n-1); else if(p>=0) return(n); } else return(n); } |
| |
Back To Question | |