Simple C program to create Calculator using Switch Statment.

C PROGRAM




#include<stdio.h>
int main()
{
float a,b;
char choice;
printf("\n Enter first number a= ");
scanf("%f",&a);
printf("\n Enter second number b= ");
scanf("%f",&b);
printf("\n Enter choice  + for addition\n Enter choice - for substraction \n Enter choice * for multiplication \n Enter choice / for division\n ");
scanf("\n %c",&choice);
printf("\n You Enterd choice is=  %c", choice);
switch(choice)
{
case '+':
printf("\n addition=%f",(a+b));
break;
case '-':
printf("\n substraction=%f",(a-b));
break;
case '*':
printf("\n Multiplication=%f",(a*b));
break;
case '/':
printf("\n Division=%f",(a/b));
break;
default:
printf("Invalid input!!");
}
return 0;
}



****Input && Output****








Post a Comment

1 Comments