Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- float add(float num1, float num2);
- float sub(float num1, float num2);
- float mult(float num1, float num2);
- float div(float num1, float num2);
- int main(){
- char op;
- float num1, num2, result = 0.0f;
- printf("Enter number, operator and number: ");
- scanf("%f %c %f", &num1, &op, &num2);
- switch(op){
- case '+':
- result = add(num1, num2);
- break;
- case '-':
- result = sub(num1, num2);
- break;
- case '*':
- result = num1 * num2;
- break;
- case '/':
- result = num1 / num2;
- default:
- printf("Enter a valid operator");
- }
- printf("%.2f %c %.2f = %.2f", num1, op, num2, result);
- return 0;
- }
- float add(float num1, float num2){
- return num1 + num2;
- }
- float sub(float num1, float num2){
- return num1 - num2;
- }
- float mult(float num1, float num2){
- return num1 * num2;
- }
- float div(float num1, float num2){
- return num1 / num2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement