C program to check whether given number is positive or negative:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <stdio.h> int main() { float n; printf("Please enter a number\n"); scanf("%f",&n); if (n==0) printf("\nEntered number is 0. It's neither positive or negative"); else if (n<0) printf("\nEntered number %.2f is negative.",n); else printf("\nEntered number %.2f is positive.",n); return 0; } |
Please enter a number
-15
Entered number -15.00 is negative.