# C Program To Perform Addition, Subtraction, Multiplication, Division and Modulus of Two Numbers

There are five fundamental arithmetic operators supported by C language, which are addition(+), subtraction(-), multiplication(*), division(/) and modulus(%) of two numbers. All arithmetic operators compute the result of specific arithmetic operation and returns its result.

## Arithmetic Operators in C

Operator Description Syntax Example
+ Adds two numbers a + b 15 + 5 = 20
- Subtracts two numbers a - b 15 - 5 = 10
* Multiplies two numbers a * b 15 * 5 = 75
/ Divides numerator by denominator a / b 15 / 5 = 3
% Returns remainder after an integer division a % b 15 % 5 = 0

## C program for addition, subtraction, multiplication, division and modulus of two numbers

This program performs basic binary arithmetic operation on two integer operands like addition, subtraction, division and modulus and prints result in screen. It first takes two integers as input from user using scanf function and stores them in 'firstNumber' and 'secondNumber' int variables and performs addition, subtraction, multiplication, division and modulus operations and stores results in 'sum', 'difference' , 'product', 'quotient' and 'modulo' variables respectively. Next, it prints the result on screen using printf function.

```#include <stdio.h>

int main(){
/* Variable declation */
int firstNumber, secondNumber;
int sum, difference, product, modulo;
float quotient;

printf("Enter First Number: ");
scanf("%d", &amp;firstNumber);
printf("Enter Second Number: ");
scanf("%d", &amp;secondNumber);

sum = firstNumber + secondNumber;
/* Subtracting two numbers */
difference = firstNumber - secondNumber;
/* Multiplying two numbers*/
product = firstNumber * secondNumber;
/* Dividing two numbers */
quotient = (float)firstNumber / secondNumber;
/* returns remainder of after an integer division */
modulo = firstNumber % secondNumber;

printf("\nSum = %d", sum);
printf("\nDifference  = %d", difference);
printf("\nMultiplication = %d", product);
printf("\nDivision = %.3f", quotient);
printf("\nRemainder = %d", modulo);

return 0;
}
```
Output
```Enter First Number: 25
Enter Second Number: 4

Sum = 29
Difference  = 21
Multiplication = 100
Division = 6.250
Remainder = 1
```

Points to Remember
• If both operands are integers, then the output is also integer and the compiler neglects the term after decimal point.
• Integer/Float = Float and Float/Integer = Float because of explicit type conversion.
• Multiplication, division and modulus operator have highest priority than addition and subtraction operator.

## C program for addition, subtraction, multiplication, division and modulus of two numbers using a function

This program uses five user defined functions 'getSum', 'getDifference', 'getProduct', 'getQuotient' and 'getModulo' to perform addition, subtraction, multiplication, division and modulus of two numbers.

```#include <stdio.h>

int getSum(int num1, int num2);
int getDifference(int num1, int num2);
int getProduct(int num1, int num2);
float getQuotient(int num1, int num2);
int getModulo(int num1, int num2);

int main(){
/* Variable declation */
int firstNumber, secondNumber;
int sum, difference, product, modulo;
float quotient;

printf("Enter First Number: ");
scanf("%d", &firstNumber);
printf("Enter Second Number: ");
scanf("%d", &secondNumber);

sum = getSum(firstNumber, secondNumber);
difference = getDifference(firstNumber, secondNumber);
product = getProduct(firstNumber, secondNumber);
quotient = getQuotient(firstNumber, secondNumber);
modulo = getModulo(firstNumber, secondNumber);

printf("\nSum = %d", sum);
printf("\nDifference  = %d", difference);
printf("\nMultiplication = %d", product);
printf("\nDivision = %.3f", quotient);
printf("\nRemainder = %d", modulo);

return 0;
}

int getSum(int num1, int num2){
int sum;
sum = num1 + num2;
return sum;
}

int getDifference(int num1, int num2){
int difference;
difference = num1 - num2;
return difference;
}

int getProduct(int num1, int num2){
int product;
product = num1 * num2;
return product;
}

float getQuotient(int num1, int num2){
float quotient;
quotient = (float)num1 / num2;
return quotient;
}

int getModulo(int num1, int num2){
int modulo;
modulo = num1 % num2;
return modulo;
}
```
Output
```Enter First Number: 25
Enter Second Number: 4

Sum = 29
Difference  = 21
Multiplication = 100
Division = 6.250
Remainder = 1
```
Related Topics
 C program to check whether an alphabet is a vowel or consonant C program for Input/Output of Integer, Character and Floating point numbers C program to check odd or even numbers C program to read and print string C program to check year is leap year or not C program to check a number is palindrome or not C program to check if two strings are anagram List of all C programs