C - Arithmetic Operators

Learn C - C tutorial - C arithmetic operators - C examples - C programs
C Arithmetic operators - Definition and Usage
- In C-Programming the Arithmetic operators is used to perform mathematical calculation such as
- Addition(+),
- Subtraction(-),
- Multiplication(*),
- Division(/) and
- Modulus(%).

Sample - C Code
#include<stdio.h>
#include<conio.h>
void main()
{
int a=20,b=10,add,sub,mul,div,mod;
add=a+b;
sub=a-b;
mul=a*b;
div=a/b;
mod=a%b;
clrscr();
printf("The addition of a,b is :%d\n",add);
printf("The subtraction of a,b is :%d\n",sub);
printf("The multiplication of a,b is :%d\n",mul);
printf("The division of a,b is :%d\n",div);
printf("The mod of a,b is :%d\n",add);
getch();
}
C Code - Explanation :

- Here we declare the variable add, sub, mul, div & mod. And assigning the value of the variable a=20 and b=10.
- In this statement we perform an arithmetic operation for the variable “a” and “b” and the output value will be stored in the variable “add”.
- In this statement we perform a subtraction operation for the variable “a” and “b” and the output value will be stored in the variable “sub”.
- In this statement we perform a multiplication operation for the variable “a” and “b” and the output value will be stored in the variable “mul” .
- In this statement we perform a division operation for the variable “a” and “b” and the output value will be stored in the variable “div” .
- In this statement we perform a mod operation for the variable “a” and “b” and the output value will be stored in the variable “mod” .
- Here “print statement” is used for printing the value of the variable “add” in the output console window, same way it displays the output for the sub, mul, div & mod operators.
Sample Output - Programming Examples

- Here the arithmetic operation for the variable “a” (value=20) and “b” (value=10) has been shown with its output result as “30”.
- Here the subtraction operation for the variable “a” (value=20) and “b” (value=10) has been shown with its output result as “10”.
- Here the multiplication operation for the variable “a” (value=20) and “b” (value=10) has been shown with its output result as “200”.
- Here the division operation for the variable “a” (value=20) and “b” (value=10) has been shown with its output result as “2”.
- Here the mod operation for the variable “a” (value=20) and “b” (value=10) has been shown with its output result as “0”.