Write a C Program (WAP) to Check the given Number is Positive or Negative using Switch Case without conditional operator

Leave a Comment
/* The following program is to judge weather a number is positive or negative. The program takes input from user in the form of characters. If the first character is '-' then its a negative number other wise its a positive one. This method is only valid for numbers that are directly entered in the program, not to any of the numerical expressions like 22*-33, in this case it will display a positive number as it has preserved 2 not the whole expression thus it funds 2 as a positive number*/

#include<stdio.h>
#include<conio.h>
void main(void)
{
char num;
clrscr();
printf("Enter a number +ve or -ve : ");
scanf("%c",&num);
switch(num)
{
case '-':
printf("Negative number");
break;
default:
printf("Positive number");
}
getch();
}



Sample Input/Output:
Write a C Program (WAP) to Check the given Number is Positive or Negative using Switch Case without conditional operator
Write a C Program (WAP) to Check the given Number is Positive or Negative using Switch Case without conditional operator

0 comments: