Created
November 14, 2015 18:59
-
-
Save qassa/9ac3f6903d9cf985c2e3 to your computer and use it in GitHub Desktop.
check if float number is negative?
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
#include <stdlib.h> | |
#include <stdio.h> | |
static int isNegative(float arg){ | |
char *p = (char*) malloc(20); | |
sprintf(p,"%f",arg); | |
return p[0] == '-'; | |
} | |
int main(){ | |
float f = -3; | |
printf("%d",isNegative(f)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment