Created
April 28, 2016 05:57
-
-
Save 78526Nasir/d7bf93579949aa5508d63d041a34bca7 to your computer and use it in GitHub Desktop.
Ceiling and Floor a number without using library function's !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Its not working for the long range values even after chaging data type