Arithmetic Operations of given two numbers in C

Definition:

Arithmetic operations in C are used to perform mathematical calculations on numbers. The common arithmetic operators are + (Addition), - (Subtraction), * (Multiplication), / (Division), and % (Modulus).

Explanation:

This topic explains how arithmetic operators work in C. Using variables and arithmetic operators, we can perform different mathematical calculations and display the results using the printf() function.


Program: Arithmetic Operations on Two Numbers

Explanation: This program performs addition, subtraction, multiplication, and division on two numbers and displays the results.


#include <stdio.h>
#include <conio.h>

    main()
{
    int a,b,add,sub,div,multi;

    clrscr();

    a=10;
    b=5;

    add=a+b;
    sub=a-b;
    div=a/b;
    multi=a*b;

    printf("\nAddition = %d",add);
    printf("\nSubtraction = %d",sub);
    printf("\nDivision = %d",div);
    printf("\nMultiplication = %d",multi);

    getch();
}

Output:

Addition = 15
Subtraction = 5
Division = 2
Multiplication = 50

Program: Modulus Operator (%)

Explanation: This program uses the modulus (%) operator to find the remainder when one number is divided by another.


#include <stdio.h>
#include <conio.h>

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

    clrscr();

    printf("Remainder = %d", a % b);

    getch();
}

Output:

Remainder = 2


Program: Division of Two Numbers

Explanation: This program divides two numbers using the division (/) operator and displays the result.


#include <stdio.h>
#include <conio.h>

    main()
{
    int a = 36, b = 6;

    clrscr();

    printf("Division = %d", a / b);

    getch();
}

Output:

Division = 6

Practice Exercises

Task 1: Write a C program to add two numbers 25 and 15.

Goal: Learn how to perform addition using the + operator.
💡 Hint: Store the numbers in variables and print the result using printf().
💡 Show Solution

#include <stdio.h>

    main()
{
    int a = 25, b = 15;

    printf("Addition = %d", a + b);

    getch();
}

Output
Addition = 40
Explanation: The + operator adds the values of two variables and displays the result using printf().
Task 2: Write a C program to multiply two numbers 8 and 9.

Goal: Practice multiplication using the * operator.
💡 Hint: Use two variables and multiply them.
💡 Show Solution

#include <stdio.h>

    main()
{
    int a = 8, b = 9;

    printf("Multiplication = %d", a * b);

    getch();
}

Output
Multiplication = 72
Explanation: The * operator multiplies the values of two variables and prints the product.
Task 3: Write a C program to divide two numbers 36 and 6 and display the result.

Goal: Learn how to use the / (division) operator.
💡 Hint: Store the numbers in variables and use the division operator inside the printf() function.
💡 Show Solution

#include <stdio.h>

    main()
{
    int a = 36, b = 6;

    printf("Division = %d", a / b);

    getch();
}

Output
Division = 6
Explanation: The / operator divides one number by another and displays the quotient.