Loading, please wait...

Arithmetic Operators

Most C programs perform arithmetic calculations. The C arithmetic operators are summarized in the following table. Note the use of various special symbols not used in algebra. The asterisk (*) indicates multiplication and the percent sign (%) denotes the remainder operator, which is introduced below.

 

The arithmetic operators are all binary operators.

 

Operator

Description

Example

+

Sum of two operands

num1 + num2 = 50

-

Difference of second operand from the first

num1 - num2 = -15

*

Multiples both operands

num1 * num2 = 150

/

Divides numerator by de-numerator

num2 / num1 = 25

%

Modulus Operator and remainder of after an   integer division.

num2 % num1 = 0

++

Increment operator increases the integer value by one.

num++ =35

--

Decrement operator decreases the integer value by one.

num-- = 10

 

Example

 

/*C program to perform all arithmetic operations*/
#include <stdio.h>
int main()
{
int num1, num2;
int sum, sub, mult, mod;
float div;
/*Read two numbers from user*/
printf("Enter any two numbers : ");
scanf("%d%d", &num1, &num2);
/*Performs all arithmetic operations*/
sum = num1 + num2;
sub = num1 - num2;
mult = num1 * num2;
div = (float)num1 / num2;
mod = num1 % num2;
/*Prints the result of all arithmetic operations*/
printf("SUM = %d \n", sum);
printf("DIFFERENCE = %d \n", sub);
printf("PRODUCT = %d \n", mult);
printf("QUOTIENT = %f \n", div);
printf("MODULUS = %d", mod);
return 0;
}

Output

     

 Enter any two numbers: 20 10

                   SUM = 30

                   DIFFERENCE = 10

                   PRODUCT = 200

                   QUOTIENT = 2.000000

                   MODULUS = 0