Computer Science, asked by karkiaditya595, 2 months ago

write a program to check given number is positive or negative​

Answers

Answered by arvgenie
1

Answer:

Explanation:

Python Program:

A) Using if...elif...else

num = float(input("Enter a number: "))

if num > 0:

  print("Positive number")

elif num == 0:

  print("Zero")

else:

  print("Negative number")

Output:

Enter a number: 2

Positive number

OR

B) Nested if

num = float(input("Enter a number: "))

if num >= 0:

  if num == 0:

      print("Zero")

  else:

      print("Positive number")

else:

  print("Negative number")

________________________________________________

C programme

A) Using 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;

}

B) Using Nested if...else

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

}

Similar questions