trunc() : Truncation of number

We will get integer part from a decimal value by using trunc() function.
trunc(x) 
x = input number

Example with float as inputs

#include <stdio.h>
#include <math.h>
int main(void){
     double    x,y;
     x=trunc(13.345);
     y=trunc(-12.456);

     printf("x=%lf , y=%lf", x,y);
     return 0;
}
The above code will give this output.
x=13.000000, y=-12.000000

Example with float variables by using truncf()

#include <stdio.h>
#include <math.h>
int main(void){
     float x,y;
     x=truncf(13.345);
     y=truncf(-12.456);
     printf("x=%f , y=%f", x,y);
     return 0;
}
Output is here
x=13.000000, y=-12.000000

Example by using truncl()

#include <stdio.h>
#include <math.h>
int main(void){
     float  x,y;
     x=truncl(13.345);
     y=truncl(-12.456);
     printf("x=%f , y=%f", x,y);
     return 0;
}
Output is here
x=13.000000, y=-12.000000
Your Rating




Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer