Arithmetic Operatorsn in C
Arithmetic operators in C are used to perform like a mathematical
calculations on numerical values. There are commonly used arithmetic
operators in C.
Operators are symbols that represence like addition, subtraction, and comparison with the programming languages. Here are some common operators in various programming languages along with their examples;
Arithmetic operators are:
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo
* Multiplication
/ Division
% Modulo
Example for Addition(+) Operator;
Program 1:
#include<stdio.h>
int main()
{
int a,b;
a=10;
b=5;
int c;
c=a+b;
printf("The sum of a and b values is:%d",c);
}
int main()
{
int a,b;
a=10;
b=5;
int c;
c=a+b;
printf("The sum of a and b values is:%d",c);
}
Output:
The sum of a and b values is:15
Program 2:
#include<stdio.h>
int main()
{
int a=6,b=5;
printf("Addition:%d",a+b);
}
int main()
{
int a=6,b=5;
printf("Addition:%d",a+b);
}
Output:
Addition:11
Example for Subtraction(-) Operator;
Program 1:
#include<stdio.h>
int main()
{
int a,b;
a=10;
b=5;
int c;
c=a-b;
printf("The value of c :%d",c);
}
int main()
{
int a,b;
a=10;
b=5;
int c;
c=a-b;
printf("The value of c :%d",c);
}
Output:
The value of c :5
Program 2:
#include<stdio.h>
int main()
{
int a=6,b=5;
printf("Subtraction:%d",a-b);
}
int main()
{
int a=6,b=5;
printf("Subtraction:%d",a-b);
}
Output:
Subtraction:1
Example for Multiplication(*) Operator;
Program 1:
#include<stdio.h>
int main()
{
int a,b;
a=10;
b=5;
int c;
c=a*b;
printf("The value of c:%d",c);
}
int main()
{
int a,b;
a=10;
b=5;
int c;
c=a*b;
printf("The value of c:%d",c);
}
Output:
The value of c:50
Program 2:
#include<stdio.h>
int main()
{
int a=6,b=5;
printf("Multiplication:%d",a*b);
}
Output:
Multiplication:30
Example for Division(/) Operator;
Program 1:
#include<stdio.h>
int main()
{
int a,b;
a=10;
b=5;
int c;
c=a/b;
printf("The value of c:%d",c);
}
int main()
{
int a,b;
a=10;
b=5;
int c;
c=a/b;
printf("The value of c:%d",c);
}
Output:
The value of c:2
Program 2:
#include<stdio.h>
int main()
{
int a=15,b=5;
printf("Division:%d",a/b);
}
Output:
Division:3
Example for Modulus(%) Operator;
Program 1:
#include<stdio.h>
int main()
{
int a,b;
a=5;
b=2;
int c;
c=a%b;
printf("The value of c:%d",c);
}
Output:
The value of c:1
Program 2:
#include<stdio.h>
int main()
{
int a=12,b=5;
printf("Modulo:%d",a%b);
}
Output:
Modulo:2
More topic in C