• Home
  • 3.1 Arithmetic Operators

3.1 Arithmetic Operators

View Categories

3.1 Arithmetic Operators

< 1 min read

Table of Contents

Arithmetic operators perform mathematical operations on numeric values. C provides operators for addition, subtraction, multiplication, division, and remainder.

#include <stdio.h>

int main()
{
    int a = 10;
    int 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("Remainder: %d\n", a % b);

    return 0;
}

Example Output #

Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3
Remainder: 1

Explanation #

The arithmetic operators used here are:

Operator Operation Example
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
/ Division a / b
% Remainder a % b

Because both a and b are int, the division is integer division:

a / b

With 10 / 3, the fractional part is discarded, producing 3.

The % operator produces the remainder of integer division. Therefore:

10 % 3

produces 1.

The % operator requires integer operands; it is not used for floating-point remainder calculations.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *