Wednesday, 30 September 2015

C Program to perform arithmetic operator using Switch statement



/*C Program to perform arithmetic operator using Switch statement*/
#include<stdio.h>
main()
{
      int num1,num2,choice;
      printf("Enter Number1  ");
      scanf("%d",&num1);
      printf("Enter Number2  ");
      scanf("%d",&num2);
      printf("\n  MENU OF ARITHMETIC OPERATION");
      printf("\n  1          ADDITION");
      printf("\n  2          SUBTRACTION");
      printf("\n  3          MULTIPLICATION");
      printf("\n  4          DIVISION");
      printf("\n Enter your choice : ");
      scanf("%d",&choice);
      switch(choice)
      {
           case 1:
                       printf("The Addition of %d + %d is %d",num1,num2,num1+num2);
                       break;
           case 2:
                       printf("The Subtraction of %d - %d is %d",num1,num2,num1-num2);
                       break;
           case 3:
                       printf("The Multiplication of %d * %d is %d",num1,num2,num1*num2);
                       break;
           case 4:
                       printf("The Division of %d / %d is %d",num1,num2,num1/num2);
                       break;
           default:
                       printf("Invalid menu choice");
                       break;
      }
}
 
 
 
 

No comments:

Post a Comment