Write a C program to compute basic arithmetic operations like addition, subtraction,
multiplication and division. Separate functions should be defined for above arithmetic
operations but the above specified functions should be invoked from another function called
mathoper( ). The parameters for mathoper( ) functions are function name, operand 1 and
operand 2.
(e.g.) mathoper(add,10,20)// add is the function for addition, 10 and 20 are operands for add
function
From main function the user have to call mathoper( ) only for doing any of the above
mentioned four arithmetic operations. Further mathoper( ) function have to call concerned
arithmetic function.
Hint: Implement the program using Function pointer concept.
Answers
Answer:
Here we will write a C
}
//function for multiplica
Here we will write a C program for addition subtraction multiplication and division using the function. First, we will create a simple program to solve the program, then we will write the same program where input is taken and the result is displayed using functions. At last, we will develop a menu-driven program, where the user has a choice, which operation he/she wants to perform addition or subtraction or multiplication or division.
C program for addition subtraction multiplication and division using the function
Program description:- C program for addition subtraction multiplication and division using the function..
#include<stdio.h>
int result;
result = n1 * n2;
display(n1, n2, '*', result);
}
//function for division of two numbers
void divide(int n1, int n2)
{
int result;
result = n1 / n2;
display(n1, n2, '/', result);
}
Output:-
Enter number: 19
Enter number: 9
19 + 9 = 28
19 – 9 = 10
19 * 9 = 171
19 / 9 = 2
Also Learn:-
Calculator program in C using functions
Factorial program in C using function
GCD of two numbers using Functions
Power of a Number using Function
Reverse a Number Using Function
Menu driven C program for addition subtraction multiplication and division using function
Program description:- Write a menu driven program to find addition, subtraction, multiplication, and division of two numbers using the user defined functions and program should eccept choice from the user repeated