Skip to content

Instantly share code, notes, and snippets.

@78526Nasir
Created April 28, 2016 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 78526Nasir/d7bf93579949aa5508d63d041a34bca7 to your computer and use it in GitHub Desktop.
Save 78526Nasir/d7bf93579949aa5508d63d041a34bca7 to your computer and use it in GitHub Desktop.
Ceiling and Floor a number without using library function's !
/* ceiling and floor a number without using library function's */
#include<stdio.h>
int CEIL(double v)
{
if(v-(int)v==0) // check weather the float variable contains a integer value or not //
return v;
else
return FLOOR(v)+1;
}
int FLOOR(double v)
{
int t;
if(v<0){
t=(int)v +(-1);
return t;
}
else return v;
}
int main()
{
printf("%d",FLOOR(-3.5));
}
@JamshaidAhmedd
Copy link

Does it work?

@sravancipher
Copy link

sravancipher commented Aug 11, 2022

Its not working for the long range values even after chaging data type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment