C Program - Calculator Using Case Statement

PROGRAM :

#include<stdio.h>
int main()
{
int a,b,c;
char opt;
printf("\nCHOOSE AN APPROPRIATE OPTION\n\nEnter + for Addition\nEnter - for Subtraction\nEnter * for Multiplication\nEnter / for Division\n\n");
scanf("%c",&opt);
printf("\nEnter two number to calculate\n");
scanf("%d%d",&a,&b);
switch(opt)
{
    case '+':
    c = a+b;
    printf("\nSum of %d and %d is %d\n",a,b,c);
    break;

    case '-':
    c = a-b;
    printf("\nDifference between %d and %d is %d\n",a,b,c);
    break;
    
    case '*':
    c = a*b;
    printf("\nMultiplication of %d by %d is %d\n",a,b,c);
    break;
    
    case '/':
    c = a/b;
    printf("\nDivision of %d by %d is %d\n",a,b,c);
    break;
    
    default :
    printf("\nInappropriate Option\n");
}
}




OUTPUT :

CHOOSE AN APPROPRIATE OPTION

Enter + for Addition
Enter - for Subtraction
Enter * for Multiplication
Enter / for Division

+

Enter two number to calculate
3
2

Sum of 3 and 2 is 5 

Post a Comment

0 Comments