C Programming - Declarations and Initializations - Discussion

5. 

How would you round off a value from 1.66 to 2.0?

[A]. ceil(1.66)
[B]. floor(1.66)
[C]. roundup(1.66)
[D]. roundto(1.66)

Answer: Option A

Explanation:

/* Example for ceil() and floor() functions: */

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

int main()
{
    printf("\n Result : %f" , ceil(1.44) );
    printf("\n Result : %f" , ceil(1.66) );
 
    printf("\n Result : %f" , floor(1.44) );    
    printf("\n Result : %f" , floor(1.66) );

    return 0;
}
// Output:
// Result : 2.000000
// Result : 2.000000
// Result : 1.000000
// Result : 1.000000

Nikita said: (Sep 20, 2010)  
What is the difference b/w ceil & floor, and also explain the work of roundup and roundto ?

Sayed Nasir said: (Oct 30, 2010)  
What is the use of ceil() and floor() function?

S.Sasikumar said: (Nov 16, 2010)  
ceil()-This function works as follows: if the value is greater than or equal to (_.5) then, it round off a value into the next integer value. Otherwise it round off into before integer value of the given float number. Floor()-This function works as follows: if the value is floating point number then it eliminates the float values and gives only integer value before the given float number.

Bhavya said: (Dec 22, 2010)  
ceil(d):double, return a value rounded up to the next higher integer.
floor(d):double,return a value rounded down to the next lower integer.

Vineettyagi said: (Dec 24, 2010)  
ceil()-This function works as follows: if the value is greater than or equal to (_.5) then, it round off a value into the next integer value

Yazhini said: (Jan 6, 2011)  
Good explanation.

Sindhu said: (Mar 3, 2011)  
What is difference between roundup() and roundto() ?

Sindhu said: (Mar 20, 2011)  
What is use of roundup and roundto?

Jhishu said: (May 17, 2011)  
Thanks to S. Sasikumar.

Teju said: (May 22, 2011)  
What is difference between roundup() and roundto().

Are they math fn's or not?

Preethi said: (May 25, 2011)  
Give the explaination of functions roundof(),roundto()

Amit Wadhe said: (May 28, 2011)  
Usage:

#include <math.h>
y = floor( x );

Where:

double x, y;


Description:

"floor" returns the largest integer (represented as a double precision number) that is less than or equal to "x".

Jayasri said: (Jun 4, 2011)  
roundup() function preforms just rounding the value 10.5 to 11
and roundto() function performs like specification if u want to display 2 decimal r three decimal. its like 123.345 u want it for 0 decimal means it displays 123. and for 1 its displays 123.3 like wise it performs

Deepika said: (Jun 18, 2011)  
Thanks to sasi.

Sudha said: (Jul 6, 2011)  
Thanks jayasri.

Parmar Vishal said: (Jul 13, 2011)  
Confusion!!! But some time both the function is give the same out put confuse!

Rakesh said: (Jul 31, 2011)  
#include<stdio.h>

#include<math.h>
void main()
{
printf("%f\n",ceil(1.69));
printf("%f",floor(1.69));
}

L.Sirisha said: (Aug 21, 2011)  
What is the difference between roundup() and ceil()?
As both are doing the same thing. ex:ceil(10.5) rounds to a next integer value.i.e.11.even roundup() do the same thing.then what is the difference between these two?

Sai Prashanthi said: (Aug 29, 2011)  
Thanks to sasi and jayashri.

Purnima said: (Sep 9, 2011)  
@sasi.

Here you are saying that for >. 5 then only the valu will round to next higest integer but if we give as ceil (2. 1) also we get ans as 3 then how?

And for roundup value is it >. 5 or may anything?

Krishna said: (Sep 12, 2011)  
Thanks for eplanation.

What is static and global variable?

Suresh said: (Sep 17, 2011)  
Dear friends, there is no functions like roundup() and roundto().

Suresh said: (Sep 17, 2011)  
There is a function as round() which gives the rusult as 4 if round(x), x ranges from 3.5 to 3.99 and it is 3 if x ranges from 3.01 to 3.49

Binit said: (Sep 29, 2011)  
ceil() - roundup a float no to its upper integer value
ex : ceil(1.9) = 2.0000
ceil(1.1) = 2.0000

floor() - roundup a float no to its lower integer value

ex : floor(1.9) = 1.0000
floor(1.1) = 1.0000

Himanshu said: (Sep 30, 2011)  
Binit and Suresh is quite right!!

Bhavana said: (Oct 5, 2011)  
Good explanation by sasikumar.

Sri said: (Oct 15, 2011)  
Roundoff means? here why we chose the ceil function only?

Deepa said: (Nov 2, 2011)  
Thanks.

Manojit said: (Feb 8, 2012)  
If I have this number, 15.4632,
If Round Up to 2 decimal, I get 15.47.
If Round to Nearest 2 decimal, I get 15.46.

Deepa said: (Feb 9, 2012)  
What is round of value and ceil () ?

Shivaprabhu said: (Mar 11, 2012)  
Good explanation by binit.

Saurav said: (Apr 24, 2012)  
What is use of ceil function?

Sravya said: (May 2, 2012)  
Good explanation by binit.

Klakston said: (May 18, 2012)  
Weather are we using roundup and roundto function for program or not?

Deepthi Sai said: (May 30, 2012)  
What is the difference between ceil() and round() ?. Please I need a clear description.

Ramamohan said: (Jul 11, 2012)  
Hi my dear friends can you explain how to use roundup and roundto functions ?

Chandan said: (Aug 25, 2012)  
I take daily life exa.
Ceil mean ceiling fan i.e. Upper limit
Floor mean ground i.e. Lower limit
Here I take upper limit mean +positive infinity n lower is -neg
Infinity

During ceil function we round value toward positive value

i.e. 3.2=4
3.6=4
2.1=3

Sri said: (Oct 17, 2012)  
Thank you for u'r logic legend explanation chandan.

Manikandan said: (Jan 19, 2013)  
What is the difference b/w ceil & floor, and also explain the work of roundup and roundto ?

What is the use of ceil() and floor() function?

Raghu Teja said: (Feb 23, 2013)  
I understood about ceil and need more clarity about floor().

Can anyone explain me about floor() with an suitable example?

Elumalai said: (Jun 3, 2013)  
Floor : It is used to eliminate the float(decimal)numbers that means if the value is 3.50 means the result is 3.00. It eliminate the .50.

Ceil : It is used to round the next integer value that means if the value is 3.50 or 3.4 the result is 4.

Round : It is used to round up or round down the float numbers based on the numbers. If the value is <3.5 then the result is 3 and >= 3.5 then v will get 4.

Alina said: (Jun 21, 2013)  
ceil(1.44) = 1.00 and roundup(1.44) = 1.00 so both are same?

Cutie said: (Jul 10, 2013)  
What is the difference between ceil & roundup and floor & roundto?

Sneha said: (Jul 25, 2013)  
What the difference between roundup() and ceil()?

Anil Soni said: (Sep 27, 2013)  
What is roundup() & why we use?

Shalini Verma said: (Sep 30, 2013)  
Give some examples of ceil() and floor() and roundup() and roundto().

Rambabu said: (Oct 12, 2013)  
Friends ceil(1.00000001)==>2.0 and floor(1.99999999)==>1.0

And there are no functions like roundup and roundto.

I think it help's to you.

Shankar said: (Mar 8, 2014)  
#include<stdio.h>
int main()
{

int x;
x=ceil(1.2) ;
printf("%f ",x);
printf("%f",ceil(1.2));
return 0;
}

Difference b/w two statement in this program.

1. x=ceil(1.2) ;
2. printf("%f",ceil(1.2));

Yogesh said: (Apr 2, 2014)  
Here you are saying that for >. 5 then only the value will round to next highest integer but if we give as ceil (2.1) also we get ans as 3 then how?

Revathi said: (Jun 18, 2014)  
Please tell me. We use roundto() instead of roundup(). Is it possible?

Akshatha said: (Jul 19, 2014)  
@Sasikumar.

You said that ceil() - This function works as follows: if the value is greater than or equal to (_.5) then, it round off a value into the next integer value.

Otherwise it round off into before integer value of the given float number, but in the explanation part they have given an example in that the o/p of ceil(1.44) is 2 how can it be? it was suppose to b 1 right?

Dhanshri said: (Aug 23, 2014)  
Friends there is no any functions like roundup() and roundto() in C language.

Poorni said: (Sep 16, 2014)  
What is mean by ceil and round to? What is the difference between ceil, roundto and roundup?

Lokesh said: (Sep 23, 2014)  
Guys ceil() function deletes the fractional value and increments the number by 1, whereas floor() function deletes the fractional part and displays the number. Here in these two functions the fractional part is not considered.

Eg:
ceil(1.66) = 2
ceil(1.10) = 2
floor(1.90)= 1
floor(1.33) = 1

Vikram said: (Sep 26, 2014)  
It is good but the people who are doing basics to under stand for them can you explain in deep manner.

Asha said: (Dec 12, 2014)  
What is an round off? How the given program get execute?

Ajay said: (Dec 29, 2014)  
The Explanation which you people were given was very good. But some people are saying one thing i.e., ceil (1.2) gives 1, and some are saying 2, may I please know the correct answer?

I am confused!

Maya said: (Mar 9, 2015)  
What is the answer if ceil (1.2)?

Does it gives 1 or 2? Please help me I was confused by various explanations over here.

Raj said: (May 4, 2015)  
@Maya the answer will be 2!

Kuldeep said: (Jul 19, 2015)  
@Maya.

The answer will be 2 because ceil() function only display the next higher integer for the given no.

Kmahender said: (Aug 6, 2015)  
I want to know about different types of functions.

Anil Chauhan said: (Sep 10, 2015)  
#include <stdio.h>
#include <math.h>

int main ()
{
float val1, val2, val3, val4;

val1 = 1.6;
val2 = 1.2;
val3 = 2.8;
val4 = 2.3;

printf ("value1 = %.1lf\n", ceil(val1));
printf ("value2 = %.1lf\n", ceil(val2));
printf ("value3 = %.1lf\n", ceil(val3));
printf ("value4 = %.1lf\n", ceil(val4));

return(0);
}

Raj said: (Oct 16, 2015)  
Why the output is 0 instead of having integer value 2?

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

int main()
{
printf("\n Result : %d" , ceil(1.44) );
printf("\n Result : %d" , ceil(1.66) );

printf("\n Result : %d" , floor(1.44) );
printf("\n Result : %d" , floor(1.66) );

return 0;

Prateek Baranwal said: (Nov 22, 2015)  
I think this function is apply the numeric rule following. Ant this function we are use of manage of memory for managing bit or byte.

Stanly said: (Jul 11, 2016)  
@Raj.

You should use to print the float value by %f instead of %d.

Hameed said: (Aug 4, 2016)  
To round off 1.66 to 2.0.

#include<stdio.h>
#include<math.h>
int main()
{
printf("Result: %4.1f",ceil(1.66));
return 0;
}

Xyz said: (Aug 11, 2016)  
When we use roundup() and ceil() functions?

Sirisha said: (Sep 23, 2016)  
What is the difference between roundup() & ceil()?

Abdulrahman said: (Dec 8, 2016)  
There is not standard function for rounding in c called roundup().

Shivkumar said: (Mar 7, 2017)  
What is difference between ceil() and floor() funtion?

Amulya said: (Jul 31, 2017)  
If ceil() round of to next value if it is greater than or equal to 5 then why is 1.44 is round off to 2.000000 and not 1.000000 it is less than 5, right?

Ranjith said: (Sep 12, 2017)  
Yes, correct @Akshatha.

Sonali said: (Sep 12, 2017)  
What is the meaning of roundup and roundto function?

Pavan Shinde said: (Apr 16, 2018)  
@All.

ceil()---> Means up.(for ex: 1.66----> 2.000000).
floor()--->Means Down.(for ex:1.44--->1.000000).

Ruchitha said: (Aug 23, 2019)  
I can't get it, please explain me guys.

V. Sai Prathyusha said: (Sep 4, 2019)  
I can't understand this. Please explain once.

V. Sai Prathyusha said: (Sep 4, 2019)  
Anyone, please write the program using four functions.

Vini said: (Apr 25, 2020)  
Thanks all for explaining it clearly.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.