Arithmetic Operators in C Programming

C Programming provide all type of arithmetic operators. Which are listed in below table.

Operators Meaning
+ Addition and unary plus
- Subtraction and Unary Minus
* Multiplication
/ Division
% Modulo Division

The Operators +, -, / and  * are work same in all programming languages. This operators are used to perform arithmetic operation variable and data.

The Unary minus is multiply it's single operator with -1 so in effect a number preceded by a minus sign changes its sign.

The Modulo Division operator is produce the remainder of an integer division. The modulo division operator cannot be used with the floating point data.

Note that c programming does not have operators for exponentiation.

ANSI C support the unary plus but the older version of C does not support it.

C programming Example for Arithmetic Operators. 
#include<stdio.h>

void main()
{

int a, b, c;
a=10;
b=5;

clrscr();

//Addition (+ operator)
c=a+b;
printf("Result after using + : %d \n",c);

//Subtraction (- operator)
c=a-b;
printf("Result after using - : %d \n",c);

//Multiplication (* operator)
c=a*b;
printf("Result after using * : %d \n",c);

//Division (/ Operator)
c=a/b;
printf("Result after using / : %d \n",c);


getch();
}




C Programming Example of Modulo Operator
#include<stdio.h>

void main()
{

int a,b,c;
a=15;
b=4;

clrscr();
c=a%b;
printf("a: %d\n",a);
printf("b: %d\n",b);
printf("Result after using modulo operator: %d",c);
getch();

}


In above example of modulo operator you can see that when we using modulo division operator with a and b than it return the remainder of division of a and b.



Next
This is the most recent post.
Older Post

0 comments:

Post a Comment