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