C Programming Lectures......calculator
/* Simple Source code to create a simple calculator for addition, subtraction, multiplication and division using switch...case statement in C programming. */
# include <stdio.h>
int main()
{
char m;
float num1,num2;
printf("Enter operator either + or - or * or / : ");
scanf("%c",&m);
printf("Enter two operands: ");
scanf("%f%f",&num1,&num2);
switch(m) {
case '+':
printf("%.1f + %.1f = %.1f",num1, num2, num1+num2);
break;
case '-':
printf("%.1f - %.1f = %.1f",num1, num2, num1-num2);
break;
case '*':
printf("%.1f * %.1f = %.1f",num1, num2, num1*num2);
break;
case '/':
printf("%.1f / %.1f = %.1f",num1, num2, num1/num2);
break;
default:
/* If operator is other than +, -, * or /, error message is shown */
printf("Error! operator is not correct");
break;
}
return 0;
}
Note-
Get Good Practice with Switch...Case in C to Create Applications Like Calculators & Other Much more Relate to Math.
Features of C Language-
- Reliability
- Portability
- Flexibility
- Interactivity
- Modularity
- Efficiency
Uses of C Language-
- Operating System Development
- Word Processors (Like MS Word)
- Spread Sheets (Like MS Excel)
- Compilers & Interpreters
- Network Drivers
- Graphics Packages (Like Photoshop)
Comments
Post a Comment