# Arithmetic Operations in C using functions

## Program Description:

Write a Program to calculate all Arithmetic Operations in C using functions, The program should accept two integer numbers from the user and perform all arithmetic operations like addition, Subtraction, Multiplication, Division, and modulo division on given numbers.

We are going to create five functions, one for each arithmetic operation, The goal of the program is to familiarize ourselves with the functions. As we have written the arithmetic operations programs earlier without using functions.

### Example Program Input and Output:

Input:

Enter two Integers: 50 3

Output:

Sum of 50+3 = 53
subtraction of 50-3 = 47
Multiplication of 50*3 = 150
Division of 50/3 = 16
ModuloDivision of 50%3 = 2

## Arithmetic Operations in C using functions Program Explanation:

As specified earlier, We are going to create a function for each arithmetic operation. So we will have five functions in the program.

Here is the prototype of the functions.

int subtract(int, int);

int product(int, int);

int division(int, int);

int moduloDivision(int, int);

As you can see from the above prototypes, All functions take two integer numbers as input and return an integer number.

### Algorithm:

1. Take two numbers from the user and store them in variables number1 and number2.
2. Call all functions one by one. Pass the number1 and number2 as the parameters and collect the return value.
• For example, We used add(number1, number2) to call the add function and passed the number1 and number2 parameters.
• The add function calculated the sum of the given number and returned the sum. ( return num1+num2;)
3. Here, We are printing the result directly using the printffunction.

## Arithmetic Operations in C using functions Program:

### Program Output – Arithmetic Operations in C using functions:

Compile and run the program using your favorite compiler, We are using the GCC compiler under Linux OS here.

Let’s try a couple of tests

As we can see from the above output, We are getting the desired output.

## Related Programs: Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

### 5 Responses

1. […] Arithmetic Operations using functions […]

2. […] Arithmetic Operations using functions […]

3. […] Arithmetic Operations using functions […]

4. […] Arithmetic Operations using functions […]

5. […] C Program to Perform Arithmetic Operations using functions […]