C trunc 函数是数学函数之一,用于返回给定数字或指定表达式的截断值。此编程中的 truncate 函数的语法为:
double trunc(double value);
trunc 函数示例
math trunc 函数允许您找到给定数字的截断值。在此程序中,我们将查找不同数字的截断值并显示输出。
#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 truncate 示例 2
在此 字符串函数 示例中,我们允许用户输入他们的值。接下来,此 程序 使用此函数来截断用户指定的值。
#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