Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //C Program to solve simple computational problems using arithmetic expressions and use of each operator leading to stimulation of a commercial calculator
- #include<stdio.h>
- void main()
- {
- float a,b;
- char op;
- printf("Enter the operator (+ - * / %%): ");
- scanf("%c",&op);
- printf("\nEnter the 2 operands: ");
- scanf("%f%f",&a,&b);
- switch(op)
- {
- case '+':
- {
- printf("%f + %f = %f",a,b,a+b);
- break;
- }
- case '-':
- {
- printf("%f - %f = %f",a,b,a-b);
- break;
- }
- case '*':
- {
- printf("%f * %f = %f",a,b,a*b);
- break;
- }
- case '/':
- {
- printf("%f / %f = %f",a,b,a/b);
- break;
- }
- case '%':
- {
- printf("%f %% %f = %d",a,b,((int)a%(int)b));
- break;
- }
- default:
- {
- printf("Enter valid operator");
- }
- }
- }
Add Comment
Please, Sign In to add comment