C program to check given number is positive, negative or neutral

Ex: write a C program to check given number is positive, negative or neutral. How to write a C program to check given number is positive negative or neutral. C program to check given number is positive, negative or neutral.


Input from user:

Enter the number: -5

Expected Output:

Given number is negative.





Step by step logic of the program:

1. Accept number from user say no.


2. Use if-else statements and relational operators to check given number is positive  or negative.

3. If number is greater than 0 then print given number is positive, otherwise if number is less than 0 then print given number is negative.

4. Otherwise print number is neutral.

5.print output on the output screen.





Program:


#include<stdio.h>

int main()
{
int no;

printf("Enter the number\n");
scanf("%d",&no);

if(no>0)
{
printf("Given number is positive\n");
}
else if(no<0)
{
printf("Given number is negative");
}
else
{
printf("Given number is neutral");
}
return 0;
}


Above program shows the following output:



C program to check given number is positive, negative  or neutral





No comments:

Post a Comment

If you have any doubts, please discuss here...👇