ceil *

[機能]

  与えられた値より大きいか等しい整数の内,最も小さい整数を double 値で返します(天井関数)

[形式]
( C/C++ の場合)

	#include <math.h>

	double ceil(double x)
		x : 倍精度浮動小数点数

( Java の場合: Math クラスの static メソッド)

	double ceil(double x)
		
[使用例]

  1. 天井関数と床関数の計算(C/C++)
    #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
    			
  2. 天井関数と床関数の計算(Java)
    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
    			
[参照]

floor

ホームページ 目次 演習解答例目次 付録目次 索引