Ceil function in C
×


Ceil function in C

232

The ceil() function in C is used to round a given floating-point number up to the nearest integer greater than or equal to the original number.

Syntax:

#include<math.h>
	
double ceil(double x);

Parameters:

x: A floating-point number to be rounded up.


Return Value:

The ceil() function returns the smallest integer that is greater than or equal to x, represented as a double.


Properties:

Rounds up the floating-point number.

Returns the value as a double type.


Examples:

1Program:

Using ceil() to round up a floating-point number.

// Program for ceil function in C
#include<stdio.h>	
include<math.h>		

int main() {
    double num = 5.3;
    double result = ceil(num);

   printf("Ceiling of %.2f is: %.2f\n", num, result);
  
   return 0;
}		

Output:

Ceiling of 5.30 is: 6.00

2Program:

Rounding up negative floating-point numbers.

// Program for ceil function in C
#include<stdio.h>	
include<math.h>	

int main() {
    double num = -4.7;
    double result = ceil(num);

    printf("Ceiling of %.2f is: %.2f\n", num, result);
   
    return 0;
}			

Output:

Ceiling of -4.70 is: -4.00

3Program :

Using ceil() with larger floating-point numbers.

#include<stdio.h>
#include<math.h>		

int main() {
    double num = 123.456;
    double result = ceil(num);

    printf("Ceiling of %.2f is: %.2f\n", num, result);
    
    return 0;
}		
	

Output:

Ceiling of 123.46 is: 124.00

4Program:

Rounding up zero and one.

// Program for ceil function in C
#include<stdio.h>	
#include<math.h>		

int main() {
    double num1 = 0.0, num2 = 1.0;
    double result1 = ceil(num1);
    double result2 = ceil(num2);

    printf("Ceiling of %.2f is: %.2f\n", num1, result1);
    printf("Ceiling of %.2f is: %.2f\n", num2, result2);
   
    return 0;
}

Output:

Ceiling of 0.00 is: 0.00
Ceiling of 1.00 is: 1.00
			


Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments