In this blog |
---|
arithmetic operators |
Aritmetic operators
operators | operation |
+ | addition |
- | subtraction |
* | Multiplication |
/ | Division |
% | Modulus |
Program illustration
#include <stdio.h>
int main()
{
int a=2,b=3;
printf("addition of b+a=%d \n",b+a); //addition
printf("subtraction of b-a=%d\n",b-a); //subtraction
printf("multiplication of b*a=%d\n",b*a); //multiplication
printf("Division of b/a=%d\n",b/a); //Division
printf("modulus of b%a=%d\n",b%a); //modulus
return 0;
}
//modulus operator gives the remainder of a division if a no is not completely divided by divisor
output:
addition of b+a=5
subtraction of b-a=1
multiplication of b*a=6
Division of b/a=1
modulus of b%a=1
(note: result of modulus operator is -ve if the first operator in -ve , eg= -10%3 =-1)
No comments:
Post a Comment