GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  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 12:26:27 #6
 zivora   Member Since: March 2009    Total Comments: 1 

RE: Fix Function
 
#include<stdio.h>
#include<conio.h>
#include<math.h>

int fix(float z)
{
    if(z>0)
    {
        return floor(z);
    }
    else if(z<0)
    {
        z--;
           return    ceil(z);
    }
    else return z;
}
void main()
{
    float x=2.5, a=-2.25;
    int fx,fa;
    fx= fix(x);
    printf("This is for 2.5 nn %d",fx);
    fa= fix(a);
    printf("This is for - 2.25 nn %d",fa);
}
     

 

Back To Question