An arithmetic operator is a symbol or a set of symbols used to perform mathematical operations on operands (variables or constants). These operations include addition, subtraction, multiplication, division, and modulus.
Operator | Description | Example | Result |
---|---|---|---|
+ | Addition (+): Adds two operands. | 5 + 3 | 8 |
- | Subtraction (-): Subtracts the right operand from the left operand. | 7 - 2 | 5 |
* | Multiplication (*): Multiplies two operands. | 4 * 6 | 24 |
/ | Division (/): Divides the left operand by the right operand. | 10 / 2 | 5 |
% | Modulus (%): Returns the remainder when the left operand is divided by the right operand. | 15 % 4 | 3 |
#include <stdio.h> int main() { int a = 5, b = 3; int sum = a + b; printf("Sum of %d and %d is: %d\n", a, b, sum); return 0; }
Sum of 5 and 3 is: 8
#include <stdio.h> int main() { int a = 7, b = 2; int difference = a - b; printf("Difference of %d and %d is: %d\n", a, b, difference); return 0; }
Difference of 7 and 2 is: 5
#include <stdio.h> int main() { int a = 4, b = 6; int product = a * b; printf("Product of %d and %d is: %d\n", a, b, product); return 0; }
Product of 4 and 6 is: 24
#include <stdio.h> int main() { int a = 10, b = 2; float quotient = (float)a / b; // Ensure floating point division printf("Quotient of %d divided by %d is: %.2f\n", a, b, quotient); return 0; }
Quotient of 10 divided by 2 is: 5.00
#include <stdio.h> int main() { int a = 15, b = 4; int remainder = a % b; printf("Remainder of %d divided by %d is: %d\n", a, b, remainder); return 0; }
Remainder of 15 divided by 4 is: 3
#include <stdio.h> int main() { int num1 = 10, num2 = 4, res; // printing num1 and num2 printf("num1 is %d \nnum2 is %d\n\n", num1, num2); res = num1 + num2; // addition printf("num1+num2 is \t%d\n", res); res = num1 - num2; // subtraction printf("num1-num2 is \t%d\n", res); res = num1 * num2; // multiplication printf("num1*num2 is \t%d\n", res); res = num1 / num2; // division printf("num1/num2 is \t%d\n", res); res = num1 % num2;// modulus // use %% if you want to print % symbol printf("num1%%num2 is \t%d\n", res); return 0; }
num1 is 10 num2 is 4 num1+num2 is 14 num1-num2 is 6 num1*num2 is 40 num1/num2 is 2 num1%num2 is 2