function in C

trunc function in C programming language

trunc function in C programming language

In this tutorial, we will discuss trunc  function in C programming language

Description

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.

 

Declaration

The declaration of the trunc() function in C programming language

double trunc(double value]);

float trunc(float value);

long double(long double value);

Parameters or arguments

parameters of trunc()  is

x- This is a floating point value

 

Returns

The trunc() function returns the truncated value from the given floating point value

 

Required Header

In the C Language, the required header file for the trunc()

#include<math.h>

Trunc function in C

Example

The following example shows the usage of trunc()  in C programming language

 

Program 1

#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

pow() function in C language

sqrt() function in C language       

cosh function   in C  language                               

sinh function in C language

tanh function in C language

abs function in C language

floor function in C language

ceil function in C language

round function in C language

 

suggested for you

Function in C language

User defined function in C language

Arithmetic functions in C Language

String function in C language

 

 

 

 

 

exp function in C programming language
pow function in C programming Language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago