“Four Function Calculator Program” is a C program to input first number, an operator and second number to perform required calculation. A sample input string is 2+4 [Press Enter]. The 4 function calculator program will add 2 and 4 and display the answer of addition that is 6.
The operators may be arithmetic operators for:
This C program uses if else if statement to check whether operator is +, -, * or / and performs the related mathematical operation and show result to the user.
The source code for plus, minus, multiplication and division calculator in C programming language is in the following code block with syntax coloring.
/*Write a C program to work as4 function calculator +, _, *, /Sample input string may be20+30[Press Enter]The c program will show answer 50*/#include<stdio.h> int main()
float num1, num2, result;
/* Input a number operator and second number from user */
printf("Enter firrst number operaor second number[ENTER]:");
printf("\nExample: 10+20[Enter]: ");
/* check the operator and perform operation accordingly */if( operator=='+')
elseif (operator =='-')
result = num1- num2;
elseif (operator =='*')
result = num1 * num2;
elseif (operator =='/')
result = num1 / num2;
printf("Invalid operator please input +, -, *, / ") ;