😸
[C] trunc 関数
機能
小数点以下を切り捨てて整数部分を返す[1]
使用例
trunc(3.7)
と表示する
\n
は改行を表す エスケープシーケンス[2]
コード
printf("%f", trunc(3.7));
全文
#include <stdio.h>
#include <math.h>
void main() {
printf("%f", trunc(3.7));
}
実行結果
3.000000
trunc(x)
を変数から表示する
コード
double x = -2.9;
printf("%f", trunc(x));
全文
#include <stdio.h>
#include <math.h>
void main() {
double x = -2.9;
printf("%f", trunc(x));
}
実行結果
-2.000000
Discussion