Checking if a number is positive, negative or zero or any character other than numbers.please check this code.Thanks in advance. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Checking if a number is positive, negative or zero or any character other than numbers.please check this code.Thanks in advance.

#include <stdio.h> void main() { int n; printf("Enter a number: "); scanf("%d", &n); switch (n > 0) { case 1: printf("Positive number"); break; case 0: switch (n < 0) { case 1: printf("Negative number"); break; case 0: switch(n == 0) { case 1: printf("zero"); break; case 0: printf("Please enter a valid number"); break; } } break; } }

30th Jul 2020, 5:51 PM
O.Naga Lakshmi Lalasa
O.Naga Lakshmi Lalasa - avatar
1 Answer
+ 1
Interesting use of switch case... But by this you are increasing more code lines... Why you don't want use if statements... But logic is creative... For code advertising pls use personal feed posts... There are special threads dedicated for code advertising.. You can find from search and use next if want... Happy coding..
30th Jul 2020, 6:03 PM
Jayakrishna 🇮🇳