Pages

Tuesday, 25 December 2012

CALCULATOR USING SWITCH CASE



/* Calculator using Switch Case */
#include<stdio.h>
#include<stdlib.h>
void main()
 {
  int a,b,c;
  float s;
  printf("\nEnter two numbers:");
  scanf("%d%d",&a,&b);
  printf(" 1.Addition  \n 2.Subtraction \n  3.multiplication \n  4.Division  \n  5.Exit \n");
  printf("\nEnter the choice:");
  scanf("%d",&c);

     switch(c)
      {
        case 1:printf("The sum is %d",a+b);
                break;
        case 2:printf("The Subtraction is %d",a-b);
                break;
        case 3:printf("The multiplication is %d",a*b);
                break;
        case 4:s=a/b;
                printf("The Division is %f",s);
                break;
        case 5:exit(0);
        default:printf("Invalid Option");
                break;
      }
 }



No comments:

Post a Comment