Menu driven program for multiple function

Write a C program using switch case statement, which provides multiple functions such as:

1. Addition
2. Subtraction
3. Multiplication
4. division
5. Remainder
6. Larger out of two numbers


Solution:

#include<stdio.h>
#include<stdlib.h>
int main()
{
     int a,b,c,ch;
     float d;
     printf("=======================");
     printf("\n\tMENU");
     printf("\n=======================");
     printf("\n 1] Addition");
     printf("\n 2] Subtraction");
     printf("\n 3] Multiplication");
     printf("\n 4] Division");
     printf("\n 5] Remainder");
     printf("\n 6] Larger out of two");
     printf("\n 0] Exit");
     printf("\n=======================\n");
     printf("Enter your choice : ");
     scanf("%d",&ch);
     printf("-----------------------\n");
     if(ch<=6 && ch>0)
     {
          printf("  Enter Two Numbers\n");
          printf("-----------------------\n");
          printf("Enter First Number  : ");
          scanf("%d", &a);
          printf("\nEnter Second Number : ");
          scanf("%d",&b);
          printf("-----------------------\n");
     }
     switch(ch)
     {
          case 1:
               c=a+b;
               printf("Addition of Numbers =  %d",c);
               break;
          case 2:
               c=a-b;
               printf("Subtraction of Numbers = %d", c);
               break;
          case 3:
               c=a*b;
               printf("Multiplication of Numbers = %d",c);
               break;
          case 4:
               d=a/(float)b;
               printf("Division of Numbers = %.2f",d);
               break;
          case 5:
               c=a%b;
               printf("Remainder of Numbers = %d", c);
               break;
          case 6:
               if(a>b)
                    printf("%d is Larger Than %d ",a,b);
               else
               if(b>a)
                    printf("%d is Larger Than %d",b,a);
               else
                    printf("%d and %d are SAME", a,b);
               break;
          case 0:
               printf("Terminated by Choice");
               exit(0); // For this function include header file stdlib.h
               break;
          default:
               printf("Invalid Choice");
     }
     return 0;
}


Output:

add sub mul div rem