Arithmetic Operator in C

Arithmetic Operator in C
Techiio-author
Written by Shuvhojit DebFebruary 7, 2022
18 min read
C
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Techiio-author
Shuvhojit Deb

Full Stack Developer

In this blog, you'll know everything about arithmetic operators.

Introduction

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.

Syntax

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.

Example #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 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;  
}  

Output

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.

Syntax

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.

Example #2

#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;  
}  

Output

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.

Syntax

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.

Example #3

#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;  
} 

Output

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.

Syntax

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.

Example #4

#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;  
}  

Output

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.

Syntax

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.

Example #5

#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.

Syntax

B = A++;  

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

Example #6

#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;  
} 

Output

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.

Syntax

B = A--;  

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

Example #7

#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;  
}  

Output

Enter the positive number: 10
The decremented value is: 9

C Language
Software
Programming
Arithmetic Operator
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance