Arithmetic Operations In C Program

Arithmetic operations in C programming are used to perform basic mathematical calculations such as addition, subtraction, multiplication, division, and modulus. These operations are performed using arithmetic operators, which are fundamental for problem-solving, logic building, and algorithm development in C.

What Are Arithmetic Operators in C?

Arithmetic operators are symbols that tell the compiler to perform mathematical operations on variables or constants.

List of Arithmetic Operators in C

Operator Name Description Example
+ Addition Adds two operands a + b
Subtraction Subtracts second operand from first a – b
* Multiplication Multiplies two operands a * b
/ Division Divides numerator by denominator a / b
% Modulus Returns remainder after division a % b

Example of Arithmetic Operations in C Program

#include <stdio.h>

int main() {
int a = 10, b = 3;

printf("Addition: %d\n", a + b);
printf("Subtraction: %d\n", a - b);
printf("Multiplication: %d\n", a * b);
printf("Division: %d\n", a / b);
printf("Modulus: %d\n", a % b);

return 0;
}

Output:

Addition: 13

Subtraction: 7

Multiplication: 30

Division: 3

Modulus: 1

Integer vs Floating-Point Arithmetic

  • Integer division discards the decimal part
    Example: 10 / 3 = 3

  • Floating-point division gives accurate results
    Example: 10.0 / 3 = 3.33

float result = 10.0 / 3;

Unary Arithmetic Operators in C

Unary operators work on one operand.

Operator Name Example
+ Unary Plus +a
Unary Minus -a
++ Increment ++a or a++
Decrement –a or a–

Example:

int x = 5; printf(“%d\n”, ++x); // Output: 6

Operator Precedence in Arithmetic Operations

Arithmetic operators follow a specific precedence:

  1. * / %

  2. + –

Example:

int result = 10 + 5 * 2; // Output: 20

Use parentheses to change precedence:

int result = (10 + 5) * 2; // Output: 30

Common Errors in Arithmetic Operations

  • Division by zero 

  • Using % with floating-point numbers 

  • Expecting decimal result from integer division 

Applications of Arithmetic Operations in C

  • Calculators

  • Loop counters

  • Algorithms and data structures

  • Financial and scientific programs

  • Embedded systems

Conclusion

Arithmetic operations in C programming form the foundation of computation. Understanding arithmetic operators, their precedence, and proper usage is essential for writing efficient and error-free C programs. Mastery of these operators helps in learning advanced concepts like expressions, loops, and algorithms.