C Program : Detect whether the entered number is even or odd


Write a Program to detect whether the enter number is even or odd. Use Nested switch() case statement.


 #include
 main()
  {
    int x, y;
    printf("\n Enter a Number : ");
    scanf("%d", &x);
    switch( x )
     {
       case 0:
           printf("\n 0 is neither even nor odd");
           break;

       case 1:
           printf("\n 1 is odd");
           break;

       default:
           y = x % 2;
           switch(y)
              {
                 case 0:
                   printf("\n Number is Even : ");
                   break;

                 default:
                   printf("\n Number is Odd : ");
                   break;

              }


     }
  }
Input : Enter a Number : 5
Output : Number is Odd

0 Komentar untuk "C Program : Detect whether the entered number is even or odd"

Back To Top