Arithmetic operators

Arithmetic operators are used to perform basic mathematical calculations.

Example

Addition, subtraction, multiplication, division, modulo operations.

Operator

Description

Example: (a=100,b=10,ans=0)

+

Add to operands

ans = a + b;   ans will be 110.

-

Subtract operand_2 form operand_1

ans = a - b;   ans will be 90.

*

Multipy two operands

ans = a * b;   ans will be 1000.

/

divides operand_1 by operand_2

ans = a / b;   ans will be 10.

%

Gives the remainder after the actual
division of operands

ans = a % b;   ans will be 0.
Because 10 will perfectly divide 100 so remainder will be zero.
8  %  3  =  2.
5  %  4  =  1.




Sample Program

Example

#include<stdio.h>

int main()
{
    int num1 = 100, num2 = 10;

    printf("num1 + num2 = %d\n",num1 + num2);
    printf("num1 - num2 = %d\n",num1 - num2);
    printf("num1 * num2 = %d\n",num1 * num2);
    printf("num1 / num2 = %d\n",num1 / num2);
    printf("num1 %% num2 = %d\n",num1 % num2);

    return 0;
}


To include % in printf, we should use %% symbol.