Arithmetic Operators in C

Preview

Arithmetic Operators in C

Arithmetic operators are used to perform mathematical calculations in a program. Various arithmetic operators in C language are as follows:

  • + [Addition Operator]
  • – [Subtraction Operator]
  • * [Multiplication Operator]
  • / [Division Operator]
  • % [Modulus Operator]



1. +

Addition operator is represented as plus (+) sign. It is used to add values of numeric variables, constants and expressions.

Example

10 + 3 = 13

2. –

Subtraction operator is represented as a hyphen (-). It is used to subtract value of one numeric quantity from another.

The quantity may be a variable, constant or expression.

Example

10 – 3 = 7

3. *

Multiplication operator is represented as an asterisk (*). It is used to multiply value of one numeric quantity with another numeric quantity.

Example

10 * 3 = 30

4. / 

Division operator is represented as a forward slash (/). It is used to divide value of one numeric quantity by another numeric quantity.

Example

10 / 3 = 3

5. %

Modulus operator is represented as a percent sign(%). It returns remainder after dividing one numeric quantity by another numeric quantity. The quantity may be a variable, constant or expression.

Example :

10 % 3 =1




Program to demonstrate

arithmetic operators.

 Output (Line Wise)

#include<stdio.h>
#include<conio.h>
int  main()
{
int a=10;
clrscr();

 

 

printf(“\nEnter value of a=”);
scanf(“%d”,&a);
Enter value of a=10
printf(“\nEnter value of b=”);
scanf(“%d”,&b);
Enter value of b=3
c=a+b;
printf(“\na+b=%d”,c);
a+b=13
c=a-b;
printf(“\na-b=%d”,c);
a-b=7
c=a*b;
printf(“\na*b=%d”,c);
a*b=30
c=a/b;
printf(“\na/b=%d”,c);
a/b=3
c=a%b;
printf(“\na%%b=%d”,c);
a%b=1
getch();
return (0);
}

 

Lesson tags: Arithmetic Operators in C, C Operators
Back to: C Programming Language