( C/C++ の場合) #include <math.h> double ceil(double x) x : 倍精度浮動小数点数 ( Java の場合: Math クラスの static メソッド) double ceil(double x)
#include <stdio.h>
#include <math.h>
int main()
{
double x;
/*
天井関数
*/
x = ceil(2.8);
printf("2.8 の ceil は %f\n", x);
x = ceil(-2.8);
printf("-2.8 の ceil は %f\n", x);
/*
床関数
*/
x = floor(2.8);
printf("2.8 の floor は %f\n", x);
x = floor(-2.8);
printf("-2.8 の floor は %f\n", x);
return 0;
}
(出力)
2.8 の ceil は 3.000000
-2.8 の ceil は -2.000000
2.8 の floor は 2.000000
-2.8 の floor は -3.000000
import java.io.*;
public class Test {
public static void main(String args[])
{
double x;
/*
天井関数
*/
x = Math.ceil(2.8);
System.out.println("2.8 の ceil は " + x);
x = Math.ceil(-2.8);
System.out.println("-2.8 の ceil は " + x);
/*
床関数
*/
x = Math.floor(2.8);
System.out.println("2.8 の floor は " + x);
x = Math.floor(-2.8);
System.out.println("-2.8 の floor は " + x);
}
}
(出力)
2.8 の ceil は 3.0
-2.8 の ceil は -2.0
2.8 の floor は 2.0
-2.8 の floor は -3.0
| ホームページ | 目次 | 演習解答例目次 | 付録目次 | 索引 |