24 Computer -- Programming Concepts and Logics

WAP to input a number and print if it is positive or not.

WAP to input a number and print if it is positive or not.

The following is a program to input a number and print if it is positive or not: 


#include <stdio.h> int main() {     double num;     printf("Enter a number: ");     scanf("%lf", &num);     if (num <= 0.0) {         if (num == 0.0)             printf("You entered 0.");         else             printf("You entered a negative number.");     }      else         printf("You entered a positive number.");     return 0; }



Or,


#include <stdio.h> int main() {     double num;     printf("Enter a number: ");     scanf("%lf", &num);     if (num < 0.0)         printf("You entered a negative number.");     else if (num > 0.0)         printf("You entered a positive number.");     else         printf("You entered 0.");     return 0; }


More questions on Programming Concepts and Logics

Close Open App