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
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…