Write a C program to check whether a number is positive or negative.
int main() {
float value;
/* get the input from the user */
printf("Enter the input value:");
scanf("%f", &value);
/* add 1 to the given input */
value = value + 1;
/* if the value is 1 or greater than 1, then positive */
if (value >= 1) {
printf("%f is positive\n", value - 1);
} else {
printf("%f is negative\n", value - 1);
}
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter the input value:-.00123
-0.001230 is negative
jp@jp-VirtualBox:~/$ ./a.out
Enter the input value:0.0123
0.012300 is positive
Enter the input value:-.00123
-0.001230 is negative
jp@jp-VirtualBox:~/$ ./a.out
Enter the input value:0.0123
0.012300 is positive
No comments:
Post a Comment