Arithmetic Operators in C Language


 Arithmetic Operators


An arithmetic operator performs mathematical operations such as addition, subtraction and multiplication on numerical values (constants and variables).

Flowing Arithmetic Operator according to their priority orders.--



Here top three has same and higher priority order as compare to bottom two. If top three or bottom two operator i.e. * / % or + - are in one instruction/line so we can solve it from associativity rule i.e. Left to Right order.

FOR EXAMPLE :-

#include <stdio.h>
int main ()
{
int a=9, b=4, c;
c= a+b;
printf("a+b = %d \n", c);
c= a-b;
printf("a-b = %d \n", c);
c= a*b;
printf("a*b = %d \n", c);
c= a/b;
printf("a/b = %d \n", c);
c= a%b;
printf("Reminder when a divided by b = %d \n", c);
return 0;
}

Output 


a+b =13
a-b =5
a*b =36
a/b =2
Reminder when divided by b=1

The operators +,- and * computes addition, subtraction and multiplication respectively as you might have expected. 
In normal calculation, 9/4= 2.25. However, the output is 2 in the program.It is because both variables a and b are integer. Hence, the output is also an integer.

The modulo operator % computes the remainder. When a=9 is divided by b=4, the remainder is 1. The % operator can only be used with integers. Please like share...



Comments

Popular posts from this blog

Important Announcements(download all my book free)

O LEVEL- INTERNET TECHNOLOGY & WEB DESIGN

Call by Reference with Pointer in C Language part-4-a