Computer Science, asked by divyanshpatel668, 4 months ago

write a program to check whether a int type number is taken as input is positive, negative or zero​

Answers

Answered by ItzMysticalBoy
2

Answer:

We can Code this in two ways:-

C Language:-

  1. If....else:-

#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;}

  • Nested if

#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;}

Similar questions