33.(C) Simple Calculator using Switch from code win
#include <stdio.h>
// simple Calculator using switch statement
/*Write a C program to create menu driven
calculator that performs basic arithmetic
operations (add, subtract, multiply and divide)
using switch case and functions. The calculator
should input two numbers and an operator from user.
It should perform operation according to the operator
entered and must take input in given format.*/
int main()
{
float a, b, result;
char operator;
scanf("%f %c %f", &a, &operator, & b);
// + , -, *, / are count as character in this program
switch (operator)
{
case '+':
printf("a+b=%.02f", result = a + b);
break;
case '-':
printf("a-b=%.02f", result = a - b);
break;
case '*':
printf("a*b=%.02f", result = a * b);
break;
case '/':
printf("a/b=%.02f", result = a / b);
break;
default:
printf("Can't Do!");
}
return 0;
}
Comments
Post a Comment