Written by **Shuvhojit Deb**February 7, 2022

18 min read

C

Full Stack Developer

Arithmetic operators are used for performing mathematical operations. C supports these operators to perform various mathematical operations such as addition, subtraction, division, multiplication, etc.

There are various operators in C which are as follows:

__Addition Operator__

It is a simple Plus (+) Operator used to add two given operands. We can use Plus Operator with different data types such as integer, float, long, double, enumerated, and string type data to add the given operand.

C = A + B;

For example, there are two operands, 5 and 6, and we want to get the sum of these numbers. Therefore, we use the '+' Operator between the given numbers that return integer data 11.

#include <stdio.h>

#include <conio.h>

int main ()

{

// declare integer variables

int num1, num2, res;

// declare float data type number

float f1, f2, res1;

// declare double variables

double d1, d2, res2;

printf (" Enter two integer numbers: ");

scanf ("%d %d", &num1, &num2);

res = num1 + num2; // use + operator

printf (" Enter two float numbers: \n ");

scanf ("%f %f", &f1, &f2);

res1 = f1 + f2; // use + operator

printf (" Enter two double data type numbers: \n ");

scanf ("%lf %lf", &d1, &d2);

res2 = d1 + d2; // use + operator

printf (" The sum of two integer numbers: %d \n", res);

printf (" The sum of two float numbers: %f \n ", res1);

printf (" The sum of two double numbers: %lf", res2);

return 0;

}

Enter two integer numbers: 25

35

Enter two float numbers:

79.21

67.79

Enter two double data type numbers:

234.123

345.341

The sum of two integer numbers: 60

The sum of two float numbers: 147.000000

The sum of two double numbers: 579.464000

__Subtraction Operator__

The minus operator is denoted by the minus (-) symbol. It is used to return the subtraction of the first number from the second number. The data type of the given number can be different types, such as int, float, double, long double, etc., in the programing language.

C = A - B;

For example, there are two operands, 15 and 6, and we want their subtraction result. So, we use the '-' Operator between the given numbers that return data 9.

#include <stdio.h>

#include <conio.h>

int main ()

{

// declare integer variables

int num1, num2, res;

// declare float data type number

float f1, f2, res1;

// declare double variables

double d1, d2, res2;

printf (" Enter two integer numbers: ");

scanf ("%d %d", &num1, &num2);

res = num1 - num2; // use + operator

printf (" Enter two float numbers: \n ");

scanf ("%f %f", &f1, &f2);

res1 = f1 - f2; // use + operator

printf (" Enter two double data type numbers: \n ");

scanf ("%lf %lf", &d1, &d2);

res2 = d1 - d2; // use + operator

printf (" The subtraction of two integer numbers: %d \n", res);

printf (" The subtraction of two float numbers: %f \n ", res1);

printf (" The subtraction of two double numbers: %lf", res2);

return 0;

}

Enter two integer numbers: 56

11

Enter two float numbers:

78.98

56.45

Enter two double data type numbers:

47789.7149

1234.7987

The subtraction of two integer numbers: 45

The subtraction of two float numbers: 22.530003

The subtraction of two double numbers: 46554.916200

__Multiplication Operator__

The multiplication operator is represented as an asterisk (*) symbol, and it is used to return the product of n1 and n2 numbers. The data type of the given number can be different types such as int, float, and double in the C programing language.

C = A * B;

For example, there are two operands 15 and 6, and we want to get their product. So, we can use the '*' Operator between the given numbers that return int data 90.

#include <stdio.h>

#include <conio.h>

int main ()

{

// declare integer variables

int num1, num2, res;

// declare float data type number

float f1, f2, res1;

// declare double variables

double d1, d2, res2;

printf (" Enter two integer numbers: ");

scanf ("%d %d", &num1, &num2);

res = num1 * num2; // use * operator

printf (" Enter two float numbers: \n ");

scanf ("%f %f", &f1, &f2);

res1 = f1 * f2; // use * operator

printf (" Enter two double data type numbers: \n ");

scanf ("%lf %lf", &d1, &d2);

res2 = d1 * d2; // use * operator

printf (" The multiplication of two integer numbers: %d \n", res);

printf (" The multiplication of two float numbers: %f \n ", res1);

printf (" The multiplication of two double numbers: %lf", res2);

return 0;

}

Enter two integer numbers: 15

12

Enter two float numbers:

2.5

3.5

Enter two double data type numbers:

234.324

798.124

The multiplication of two integer numbers: 180

The multiplication of two float numbers: 8.750000

The multiplication of two double numbers: 187019.608176

__Division Operator__

The division operator is an arithmetic operator that divides the first (n1) by the second (n2) number. Using division operator (/), we can divide the int, float, double and long data types variables.

C = A / B;

For example, there are two operands, 25.5 and 5.0, and we want to get their division result. So, we use the '/' Operator between the given numbers that return float data 5.1.

#include <stdio.h>

#include <conio.h>

int main ()

{

// declare integer variables

int num1, num2, res;

// declare float data type number

float f1, f2, res1;

// declare double variables

double d1, d2, res2;

printf (" Enter two integer numbers: ");

scanf ("%d %d", &num1, &num2);

res = num1 / num2; // use / operator

printf (" Enter two float numbers: \n ");

scanf ("%f %f", &f1, &f2);

res1 = f1 / f2; // use / operator

printf (" Enter two double data type numbers: \n ");

scanf ("%lf %lf", &d1, &d2);

res2 = d1 / d2; // use / operator

printf (" The division of two integer numbers: %d \n", res);

printf (" The division of two float numbers: %f \n ", res1);

printf (" The division of two double numbers: %lf", res2);

return 0;

}

Enter two integer numbers: 125

15

Enter two float numbers:

214.32

248.56

Enter two double data type numbers:

4243.7691

687.434

The division of two integer numbers: 8

The division of two float numbers: 0.862247

The division of two double numbers: 6.173348

**Modulus Operator**

The modulus operator is represented by the percentage sign (%), and it is used to return the remainder by dividing the first number by the second number.

C = A % B;

For example, there are two operands 25 and 4, and we want to get their modulus result. So, we use the '%' operator in between the given numbers that return remainder 1.

#include <stdio.h>

#include <conio.h>

int main ()

{

// declare integer variables

int num1, num2, res;

printf (" Enter two integer numbers: ");

scanf ("%d %d", &num1, &num2);

res = num1 % num2; // use % operator

printf (" The modulus of two integer numbers: %d \n", res);

return 0;

}

Output

Enter two integer numbers: 35

3

The modulus of two integer numbers: 2

__Increment Operator__

Increment Operator is the type of Arithmetic operator, which is denoted by double plus (++) operator. It is used to increase the integer value by 1.

B = A++;

For example, suppose the integer value of A is 10, the increment operator increases the operand value by 1, which returns 11.

#include <stdio.h>

#include <conio.h>

int main ()

{

// declare integer variables

int num1, res;

printf (" Enter the positive number: ");

scanf ("%d", &num1);

res = num1++; // use increment operator

printf (" The incremented value is: %d ", num1);

return 0;

}

Enter the positive number: 10

The incremented value is: 11

__Decrement Operator__

Decrement Operator is denoted by the double minus (--) symbol, which decreases the operand value by 1.

B = A--;

For example, suppose the integer value of A is 10, the decrement operator decreases the operand value by 1 that returns 9.

#include <stdio.h>

#include <conio.h>

int main ()

{

// declare integer variables

int num1, res;

printf (" Enter the positive number: ");

scanf ("%d", &num1);

res = num1--; // use decrement operator

printf (" The decremented value is: %d ", num1);

return 0;

}

Enter the positive number: 10

The decremented value is: 9

C Language

Software

Programming

Arithmetic Operator

Was this blog helpful?

Trending Technologies

15

Software40

DevOps46

Frontend Development24

Backend Development20

Server Administration17

Linux Administration26

Data Center24

Sentry24

Terraform23

Ansible83

Docker70

Penetration Testing16

Kubernetes21

NGINX20

JenkinsX17

Recommended Blogs

8

Recommended Threads

8

Anik Adhikary

Anik Adhikary

Anik Adhikary