C program to perform all arithmetic operations

Category: C Program

Write a C program to enter two numbers and perform all arithmetic operations like addition, subtraction etc to understand how to perform basic arithmetic operations in C language.

In this program we are going to perform all basic operations like addition, subtraction, multiplication, division, modulus and finding quotient of two numbers.

Example

Input: Enter first number: 20
       Enter second number: 10

Output: Sum = 30
        Difference = 10
        Multiply = 200
        Modulus = 0
        Quotient = 2

C program to perform all arithmetic operations

#include <stdio.h>

void main()
{
    int num1, num2;
    int sum, diff, mul, div, mod, quo;

    printf("Enter first number: ");
    scanf("%d", &num1);
    printf("Enter second number: ");
    scanf("%d", &num2);

    sum = num1 + num2;
    diff = num1 - num2;
    mul = num1 * num2;
    mod = num1 % num2;
    quo = num1 / num2;

    printf("Sum = %d\n", sum);
    printf("Difference = %d\n", diff);
    printf("Multiply = %d\n", mul);
    printf("Modulus = %d\n", mod);
    printf("Quotient = %d\n", quo);
}

Output

Enter first number: 20
Enter second number: 10
Sum = 30
Difference = 10
Multiply = 200
Modulus = 0
Quotient = 2

Recommended Posts