Skip to main content

Arithmetic Operators

Arithmetic operators

Arithmetic operators are special symbols in C that perform specific mathematical operations on one, two, or three operands, and then return a result.

Below are the Arithmetic operators in C with a brief description:

OperatorDescriptionExampleResult
+Adds two operands.5 + 1015
-Subtracts the second operand from the first.10 - 55
*Multiplies the operands.5 * 1575
/Divides the first operand by the second.15 / 53
%Returns the remainder of the division of the first operand by the second.7 % 31

Examples of Arithmetic operators:

Example 1:

#include <stdio.h>

int main() {
int x = 5, y = 10, z = 15;

// Addition operator
int sum = x + y; // sum = 15
printf("%d + %d = %d\n", x, y, sum);

// Subtraction operator
int difference = y - x; // difference = 5
printf("%d - %d = %d\n", y, x, difference);

// Multiplication operator
int product = x * z; // product = 75
printf("%d * %d = %d\n", x, z, product);

// Division operator
int quotient = z / x; // quotient = 3
printf("%d / %d = %d\n", z, x, quotient);

// Modulus operator
int remainder = y % x; // remainder = 0
printf("%d %% %d = %d\n", y, x, remainder);
return 0;
}
Output:

Explanation

The program uses the following arithmetic operators:

  • The addition operator (+) is used to add two operands (x and y) together. The result is stored in the variable sum, which is then printed using the printf function.

  • The subtraction operator (-) is used to subtract one operand (x) from another (y). The result is stored in the variable difference, which is then printed using the printf function.

  • The multiplication operator (*) is used to multiply two operands (x and z) together. The result is stored in the variable product, which is then printed using the printf function.

  • The division operator (/) is used to divide one operand (z) by another (x). The result is stored in the variable quotient, which is then printed using the printf function.

  • The modulus operator (%) is used to find the remainder when one operand (y) is divided by another (x). The result is stored in the variable remainder, which is then printed using the printf function.

When run, this program will print:

5 + 10 = 15
10 - 5 = 5
5 * 15 = 75
15 / 5 = 3
10 % 5 = 0
/ vs %

Please note that in C, the division operator (/) will return the quotient of the division and the modulus operator (%) returns the remainder of the division.