Arithmetic Operators In C





An arithmetic operator is a symbol or a set of symbols used to perform mathematical operations on operands (variables or constants). These operations include addition, subtraction, multiplication, division, and modulus.

Here are the common arithmetic operators:

Arithmetic Operators In C With Example
Operator Description Example Result
+ Addition (+): Adds two operands. 5 + 3 8
- Subtraction (-): Subtracts the right operand from the left operand. 7 - 2 5
* Multiplication (*): Multiplies two operands. 4 * 6 24
/ Division (/): Divides the left operand by the right operand. 10 / 2 5
% Modulus (%): Returns the remainder when the left operand is divided by the right operand. 15 % 4 3


C program to add two numbers a and b and store the result in a variable sum. Print the sum along with the original numbers.

#include <stdio.h>

int main() {
    int a = 5, b = 3;
    int sum = a + b;
    printf("Sum of %d and %d is: %d\n", a, b, sum);
    return 0;
}
Output:
Sum of 5 and 3 is: 8    


C program to subtract two numbers a and b. Store the result in a variable difference. Display the difference along with the original numbers.

#include <stdio.h>

int main() {
    int a = 7, b = 2;
    int difference = a - b;
    printf("Difference of %d and %d is: %d\n", a, b, difference);
    return 0;
}
Output:
Difference of 7 and 2 is: 5    


C program to multiply two numbers a and b. Save the product in a variable product. Output the product along with the original numbers.

#include <stdio.h>

int main() {
    int a = 4, b = 6;
    int product = a * b;
    printf("Product of %d and %d is: %d\n", a, b, product);
    return 0;
}
Output:
Product of 4 and 6 is: 24    


C program to divide two numbers a and b. Store the quotient in a variable quotient. Print the quotient with two decimal places, along with the original numbers.

#include <stdio.h>

int main() {
    int a = 10, b = 2;
    float quotient = (float)a / b; // Ensure floating point division
    printf("Quotient of %d divided by %d is: %.2f\n", a, b, quotient);
    return 0;
}
Output:
Quotient of 10 divided by 2 is: 5.00    


C program to find the remainder when one number a is divided by another number b. Save the remainder in a variable remainder. Display the remainder along with the original numbers.

#include <stdio.h>

int main() {
    int a = 15, b = 4;
    int remainder = a % b;
    printf("Remainder of %d divided by %d is: %d\n", a, b, remainder);
    return 0;
}
Output:
Remainder of 15 divided by 4 is: 3    


C program to demonstrate working of binary arithmetic operators all together.

#include <stdio.h>
int main()
{
	int num1 = 10, num2 = 4, res;
	// printing num1 and num2
	printf("num1 is %d \nnum2 is %d\n\n", num1, num2);

	res = num1 + num2; // addition
	printf("num1+num2 is \t%d\n", res);

	res = num1 - num2; // subtraction
	printf("num1-num2 is \t%d\n", res);

	res = num1 * num2; // multiplication
	printf("num1*num2 is \t%d\n", res);

	res = num1 / num2; // division
	printf("num1/num2 is \t%d\n", res);

	res = num1 % num2;// modulus
	// use %% if you want to print % symbol
	printf("num1%%num2 is \t%d\n", res); 
	return 0;
}
Output:
num1 is 10
num2 is 4

num1+num2 is    14
num1-num2 is    6
num1*num2 is    40
num1/num2 is    2
num1%num2 is    2