Thursday, 10 March 2016

C Program For Calculator Using Switch Case

#include
#include

main()
{
char choice;
int a,b,res=0;
//Ghanendra Yadav
printf("Enter first value: ");
scanf("%d",&a);
printf("\n Enter operator: ");
choice=getch();
printf("\n Enter second value: ");
scanf("%d",&b);

switch(choice)
{
case '+':
  res=a+b;
  printf("Sum: %d",res);
break;
case '-':
  res=a-b;
  printf("Difference: %d",res);
break;
case '*':
  res=a*b;
  printf("Product: %d",res);
break;
case '/':
  res=a/b;
  printf("Quotient: %d",res);
break;
default:
  printf("Enter Valid Operator!!");
}
getch();
}

Output:-


No comments:
Write comments

Recommended Posts × +