In this tutorial, we will discuss trunc function in C programming language
The trunc() math function in C programming language returns the truncated value from the floating point value and return integer value..
trunc() : This function truncates the decimal value from floating point value and returns an integer value.
The declaration of the trunc() function in C programming language
double trunc(double value]); float trunc(float value); long double(long double value);
parameters of trunc() is
x- This is a floating point value
The trunc() function returns the truncated value from the given floating point value
In the C Language, the required header file for the trunc()
#include<math.h>
The following example shows the usage of trunc() in C programming language
#include <stdio.h> #include <math.h> int main() { double x=17.07,y=46.107,z=234.867; printf("truncated value of %f is %f\n",x,trunc(x)); printf("truncated value of %f is %f\n",y,trunc(y)); printf("truncated value of %f is %f\n",y,trunc(z)); getch(); return 0; }
When the above program is compiled, it will produce the following result
truncated value of 17.070000 is 17.000000 truncated value of 46.107000 is 46.000000 truncated value of 234.867000 is 234.000000
Program 2
#include <stdio.h> #include <math.h> int main() { //define the variable double truncValue; double inputValue; //get input from user printf("Please enter the value to calculate trunc value :"); scanf("%lf",&inputValue); //calculate the trunc value truncValue=trunc(inputValue); //display the trunc value printf("\nTruncated value of %lf is %lf\n",inputValue,truncValue); getch(); return 0; }
When the above program is compiled, it will produce the following result
Please enter the value to calculate trunc value :56.7899 Truncated value of 56.890 is 56.000000
Similar functions
Other C programming language functions that are similar to this function
suggested for you
User defined function in C language
Arithmetic functions in C Language
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…