C Arithmetic Operators
Description
Arithmetic operators are +, -, *, \ and the modulus operator %. % cannot be used for float data type or double data type.
Arithmetic Operators in C
The following table lists all C Arithmetic Operators.
Operator | Description | Example |
---|---|---|
* | Multiplication | Result = Operand1 * Operand2; |
/ | Division | Result = Operand1 / Operand2; |
% | Modulus (remainder) | Remainder = Operand1 % Operand2; |
+ | Addition | Result = Operand1 + Operand2; |
- | Subtraction | Result = Operand1 -Operand2; |
Example - C Arithmetic Operators
#include<stdio.h>
/* www . j a v a2 s .c o m*/
main(){
int a = 1,b = 2,c = 3,d = 4;
int sum,sub,mul,rem;
float div;
sum = b+c;
sub = b-c;
mul = b*c;
div = b/c;
rem = b%d;
a = b/c * d;
printf("\n sum = %d, sub = %d, mul = %d, div = %f",sum,sub,mul,div);
printf("\n remainder of division of b & d is %d",rem);
printf("\n a = %d",a);
}