C Categories


Arithmetic Operators
Description
The four most common arithmetic operators are +, , * and / for addition, substraction, multiplication and division are used in same way as regular algebric calcluations. Modulus operator is a new operator represented by percent (%) symbol, which computes the remainder of division operation, also called as remainder operator. These operators work on data types like integer, float and double.
Below is an example that shows the use of arithmetic and modulus operators.
Source code
 //Using arithmetic operators
 #include <stdio.h>
 #include <conio.h>
 void main()
 {
int a,b,c;
float fa,fb,fc;
clrscr();
printf("Enter value of a : ");
scanf("%d",&a);
printf("Enter value of b : ");
scanf("%d",&b);
c=a+b;
printf("\nAddition is : %d",c);
c=ab;
printf("\nSubstraction is : %d",c);
c=a*b;
printf("\nMultiplication is : %d",c);
fa=a;
fb=b;
fc=(fa/fb);
printf("\nDivision is : %.2f",fc);
c=a%b;
printf("\nRemainder is : %d",c);
getch();
 }
Program working steps
 First line is the comment, 2nd and 3rd line are preprocessor directive statements which include definition of printf, scanf, clrscr functions.
 Void main() is the function where program execution starts.
 Declaration of some integer and float variables.
 Printf statement displays the output to enter the number and scanf stores the input number entered into the variable.
 At line no.14 c=a+b; statement adds the value of a and b variable, and stores the result in variable c. Similar to this statement others statement on line no.16,18,22 and 24 results are being calculated and displayed accordingly.


Tip Box
Operator precedence
Priority 
Operator 
1st 
* 
2nd 
/ 
3rd 
% 
4th 
+ 
5th 
 

