Check number is even or odd - C Program

C program to check entered number is even or odd, using nested switch case.

Solution:

#include<stdio.h>
int main()
{
     int n,r;
     printf("Enter a Number : ");
     scanf("%d",&n);
     printf("---------------------\n   ");
     switch(n)
     {
          case 0:
               printf("Number is Even");
               break;
          case 1:
               printf("Number is Odd");
               break;
          default:
               r=n%2;
               switch(r)
               {
                    case 0:
                         printf("Number is Even");
                         break;
                    default:
                         printf("Number is Odd");
               }
     }
     return 0;
}


Output:

even odd nested switch