Arithmetic Operators
C language supports arithmetic operators as +, -, *, /, and % operators used to perform addition, subtraction, multiplication, division and remainder operations. Any expression that forms with the combination of operands and arithmetic operators is termed as an arithmetic expression.
- Arithmetic operators are binary operators. Since, they required two operands to perform the operation.
- Modulo operator (%) can’t be applied on floating point numbers.
Modulo operator (%) can’t be applied on floating point numbers.
Example program for C arithmetic operators:
• In this example program, two values “40″ and “20″ are used to perform arithmetic operations such as addition, subtraction, multiplication, division, modulus and output is displayed for each operation.
main()
{
int a,b;
clrscr();
printf("Enter a,b values:");
scanf("%d%d",&a,&b);
printf(“Addition of a, b is : %d\n”, a+b);
printf(“Subtraction of a, b is : %d\n”, a-b);
printf(“Multiplication of a, b is : %d\n”,a*b);
printf(“Division of a, b is : %d\n”, a/b);
printf(“Modulus of a, b is : %d\n”, a%b);
getch();
}
No comments:
Post a Comment