Pages

Visitors

Thursday, 22 December 2011

Calculator by Switch statement


#include<stdio.h>


main()
{
   int n,a,b,c;


   printf(" enter values of two operands : ");


   scanf("%d%d",&a,&b);


   printf("Chose Operation \n1.Addition\n2.subtraction\n3.multiplication\n4.division\n");


          scanf("%d",&n);


          switch(n)


          {
              case 1 : c = a+b;
              printf("a+b is %d",c);
              break;


              case 2: c = a-b;
              printf("a-b is %d",c);
              break;


              case 3 : c = a*b;
              printf("a*b is %d",c);
              break;
              case 4:c = a/b;
              printf("a/b is %d",c);
              break;


              default : printf("wrong option");
          }


   getch();
}

No comments:

Post a Comment