C trunc function

The C trunc function is one of the math Functions used to return the truncated value of a given number or a specified expression. The syntax of the truncate function in this Programming is

double trunc(double value);

C trunc Function Example

The math trunc Function allows you to find the truncated value of a given number. In this program, we are going to find the truncated value of different numbers and display the output.

#include <stdio.h>
#include <math.h>

int main()
{
    printf("\n The Truncated Value of 0.75    = %.2f ", trunc(0.75));
    printf("\n The Truncated Value of 15.25   = %.2f ", trunc(15.25));
    printf("\n The Truncated Value of 152.50  = %.2f ", trunc(152.50));
    
    printf("\n The Truncated Value of -14.36  = %.2f ", trunc(-14.36));
    printf("\n The Truncated Value of -26.82  = %.2f ", trunc(-26.82));
    printf("\n The Truncated Value of -90.55  = %.2f \n", trunc(-90.55));
    
    return 0;
}
C trunc function example 1

C truncate Example 2

In this String Function example, we are allowing a user to enter their value. Next, this program uses this function to truncate the user-specified value.

#include <stdio.h>
#include <math.h> 

int main()
{
    float number, trunc_Value;
    
    printf(" Please Enter any Numeric to Round :  ");
    scanf("%f", &number);
    
    trunc_Value = trunc(number);
    
    printf("\n The Result of %.2f = %.4f \n", number, trunc_Value);
    
    return 0;
}
 Please Enter any Numeric to Round :  234.589

 The Result of 234.59 = 234.0000 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.