Illustration of arithmetic operators used in C programming with sample code

Arithmetic Operator:

The C arithmetic operator’s operator work on two operands. C provides 5 Binary Arithmetic Operators.
An arithmetic operator performs mathematical operations such as addition, subtraction, multiplication, division etc. on numerical values (constants and variables).

Addition(+): + Operator is used to perform addition of two variable or operands. e.g z=x+y

Substaction(-): - Operator is used to perform substraction of two variable or operands. e.g z=x-y


Multiplcation(*): - Operator is used to perform multiplication of two variable or operands. e.g z=x*y

Division(/): - Operator is used to perform Division of two variable or operands. e.g z=x/y

Modulus or Modulo(%): - Operator is used to perform modulo division (or finds the remainder)of two variable or operands. e.g z=x%y

Example 1: Arithmetic Operators in c Language


Let undestand the arithmetic operator using following example with explanation.
/* Working of arithmetic operators in c language */
#include <stdio.h>
int main()
{
int x = 9,y = 4, z; /* integer variable declared and assigned values i.e x=9,y=4, no value for z */
z = x+y;
printf("x+y = %d \n",z);
z = x-y;
printf("x-y= %d \n",z);
z = x*y;
printf("x*y = %d \n",z);
z = x/y;
printf("x/y = %d \n",z);`
z = x%y;
printf("Remainder when %d divided by %d = %d \n",x,y,z);
return 0;
}
Output
x+y = 13
x-y = 5
x*y = 36
x/y = 2
Remainder when x divided by y=1

Program Explanation:
This program demonstrates how various arithmetic operators work in the C programming language. Arithmetic operators are the backbone of any mathematical or logical program. Now, let's break the program down and see what meaning is derived from each line of code to the output.
________________________________________
/* Working of arithmetic operators in C language */
#include <stdio.h>
The first statement includes the standard input/output library <stdio.h> with the purpose of using the input/output functions such as printf() to display output.
________________________________________
int main()
{
int x = 9, y = 4, z;
In the main function:
• It declares three integer variables:
o x has a value of 9.
o y has a value of 4.
o z is very much left uninitialized now and will be used to hold and display the results of various operations going on.
This is a neat and clean way to declare and initialize variables in C.
________________________________________
➕ 1. Addition Operation
z = x + y;
printf("x+y = %d \n", z);
Here, we add x and y (i.e., 9 + 4 = 13).
The result is stored in z and then displayed using printf. The %d format tells the compiler to print an integer.
________________________________________
➖ 2. Subtraction Operation
z = x - y;
printf("x-y = %d \n", z);
In this case, we will subtract 4 from 9, which results in 5. This result is kept in z and printed. Subtraction is a simple operation, but in certain cases it can be applied in age calculations or date difference and balance calculations.
________________________________________
✖️ 3. Multiplication Operation
z = x * y;
printf("x*y = %d \n", z);
Multiplying 9 and 4 gives us 36, which again is stored in z and printed. This operator is heavily used in mathematical and scientific computations.
________________________________________
/ 4. Integer Division Operation
z = x / y;
printf("x/y = %d \n", z);
Now comes an important concept. In C, if you divide with two integers, the result is also an integer which means the decimal part will be thrown away. So, 9 divided by 4 will result in 2 and not 2.25. The fraction will just be dropped. This is known as integer division.
Tip: The operand must not be an int if you want a precise answer, e.g., 2.25. One of the operands should be a float.
________________________________________
% 5. Modulus (Remainder) Operation
z = x % y;
printf("Remainder when %d divided by %d = %d \n", x, y, z);
This gives the remainder when one number is divided against the other. Now when 9 gets divided against 4, we have Quotient = 2 · Remainder = 1 Especially helpful is the % operator in verifying divisibility (like on even or odd numbers)
________________________________________
Last Line
return 0;
This concludes the main() function and hands back control to the operating system, indicating that the program terminated successfully.
________________________________________
Output
x+y = 13
x-y = 5
x*y = 36
x/y = 2
Remainder when 9 divided by 4 = 1
________________________________________
Summary and Learning:
This tiny program introduces the five most basic arithmetic operators in an easy way:
Operator Symbol Function
Addition + Add two numbers
Subtract - Subtract Second from First
Multiply * Multiply two Numbers
Divide / Divide & return only the quotient
Modulus % Returns the remainder after division
________________________________________
Why It Requires:
Arithmetic operation is very little confined to math problems but it mixes itself in one or the other form into real-life examples of programming — billing systems, games, reports, finance, applications, IoT sensors wherever one is doing values, it needs to be asserted with these.


Prev. Topic=> Introduction C Assignments  Next Topic: Assignment Operators