#include <stdio.h>
int main() {
printf("Output = %.4f", trunc(14.23)); // Output = 14.0000
printf("\nOutput = %.4f", trunc(4.831)); // Output = 4.0000
printf("\nOutput = %.4f", trunc(-17.831)); // Output = -17.0000
printf("\nOutput = %.4f", trunc(-22.23)); // Output = -22.0000
return 0;
}
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
Syntax
trunc(x)
x = input number