Thursday, 16 January 2020

c programming code for simple calculator

       c programming code for simple calculator
 Here is the code for writing c programming code for menu driven calculator doing addition ,subtraction,division and multiplication using switch case.

#include<stdio.h>
int main()
{
    int a,b,choice;
    printf("enter any two numbers\n");
    scanf("%d%d",&a,&b)
   do
  {
    printf("\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Exit\n");
    printf("enter any choice\n");
    scanf("%d",&choice);
    switch(choice)
    {
    case 1:
        if(choice==1)
            printf("addition of given number is %d",a+b);
        break;
    case 2:
        if(choice ==2)
            printf("subtraction of given numbers is %d",a-b);
            break;
    case 3:
        if(choice ==3)
            printf("multiplication of given numbers is %d",a*b);
            break;
    case 4:
        if(choice==4)
            printf("division of given numbers is %d",a/b);
        break;
    default:
        printf("invalid choice \n");
    }
}
while(choice!=5);
}

Result of the above program

3 comments: