Arithmetic Operators in C

Arithmetic operators are used to perform mathematical arithmetic operations. such as addition, subtraction, multiplication, division and mod operation.

C Language supports five arithmetic operators.



Arithmetic Operators in C

NameOperatorExample
Addition +a + b
Subtraction a – b
Multiplication*a * b
Division/a / b
Mod%a % b


Addition in C ( + )

Arithmetic addition operator is ‘+’. Arithmetic addition operator is used to perform basic mathematical addition operation between two operands.

#include <stdio.h>

int main(int argc, char** argv) {
	int a = 8;
	int b = 2;
	int c = 0;
	
	c = a + b;
	
	printf("a value is : %d\n", a); 
	printf("b value is : %d\n", b);
	printf("\n"); 
	printf("(a + b) is : %d\n", c); 
	
	return 0;
}

Output

a value is : 8
b value is : 2

(a + b) is : 10


Subtraction in C ( – )

Arithmetic subtraction operator is ‘-‘. Arithmetic subtraction operator is used to perform basic mathematical subtract operation between two operands.

#include <stdio.h>

int main(int argc, char** argv) {
	int a = 8;
	int b = 2;
	int c = 0;
	
	c = a - b;
	
	printf("a value is : %d\n", a); 
	printf("b value is : %d\n", b);
	printf("\n"); 
	printf("(a - b) is : %d\n", c); 
	
	return 0;
}

Output

a value is : 8
b value is : 2

(a - b) is : 6


Multiplication in C ( * )

Arithmetic multiplication operator is ‘*’. Arithmetic multiplication operator is used to perform basic mathematical multiply operation between two operands.

#include <stdio.h>

int main(int argc, char** argv) {
	int a = 8;
	int b = 2;
	int c = 0;
	
	c = a * b;
	
	printf("a value is : %d\n", a); 
	printf("b value is : %d\n", b);
	printf("\n"); 
	printf("(a * b) is : %d\n", c); 
	
	return 0;
}

Output

a value is : 8
b value is : 2

(a * b) is : 16


Division in C ( / )

Arithmetic division operator is ‘/’. Arithmetic division operator is used to perform basic mathematical dividing operation between two operands.

#include <stdio.h>

int main(int argc, char** argv) {
	int a = 8;
	int b = 2;
	int c = 0;
	
	c = a / b;
	
	printf("a value is : %d\n", a); 
	printf("b value is : %d\n", b);
	printf("\n"); 
	printf("(a / b) is : %d\n", c); 
	
	return 0;
}

Output

a value is : 8
b value is : 2

(a / b) is : 4


Mod in C ( % )

Arithmetic mod operator is ‘%’. Arithmetic mod operator is used to perform basic mathematical mod operation between two operands which returns the remainder.

#include <stdio.h>

int main(int argc, char** argv) {
	int a = 8;
	int b = 2;
	int c = 0;
	
	c = a % b;
	
	printf("a value is : %d\n", a); 
	printf("b value is : %d\n", b);
	printf("\n"); 
	printf("(a % b) is : %d\n", c); 
	
	return 0;
}

Output

a value is : 8
b value is : 2

(a % b) is : 0



Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *