QUESTION: C Program to Arithmetic Calculator using switch case Statements
#include <stdio.h>
#include <conio.h>
void main()
{
int a , b, result;
char choice;
printf("enter a number and athematic operator: \n");
printf("enter a frist number: \n");
scanf("%d", &a);
printf("Enter operator: \n");
choice=getch();
printf("Enter second value: \n");
scanf("%d",&b);
switch(choice){
case '+':
result = a+b;
printf("addition of %d and %d is %d ",a, b, result);
break;
case '-':
result = a-b;
printf("subtraction of %d and %d is %d ", a, b, result);
break;
case '*':
result = a*b;
printf("muliplication of %d and %d is %d ",a, b, result);
break;
case '/':
result = a/b;
printf("division of %d and %d is %d ",a, b, result);
break;
case '%':
result = a%b;
printf("remainder after dividing %d and %d is %d",a, b, result);
break;
}
getch();
}
OUTPUT
enter a number and athematic operator:
enter a frist number:
40
Enter operator:
Enter second value:
4
muliplication of 40 and 4 is 160
0 Comments