Header Ads

Simple Calculator Using Switch Statement



Simple calculator using switch statement

Code:

#include<stdio.h>

 main()

{ int a,b,c,choice;

  printf("Enter the value of a:")

  scanf("%d",&a);

   printf("Enter the value of b:");

   scanf("%d",&b);

   printf("Enter your choice\n");

   printf("1.for addition\n");

   printf("2.for subtraction\n");

   printf("3.for multiplication\n");

   printf("4.for division\n");

   printf("\n enter your choice\n");

   scanf("%c",&choice);

   choice=getch();

   switch(choice)

    {case '1':
        c=a+b;

        printf("%d+%d=%d",a,b,c);

        break;

    case '2':
        c=a-b

        printf("%d-%d=%d",a,b,c);

        break;

    case '3':

        c=a*b;

        printf("%d*%d=%d",a,b,c);

        break;

    case '4':

        c=a/b;

        printf("%d/%d=%d",a,b,c);

        break;

    default:

   printf("invalid choice!!!");   }

    getch();}

Output:

No comments

Powered by Blogger.