C PROGRAMMING PROGRAM • OPERATORS & CONVERSIONS

Perform All Arithmetic Operations

Learn how to perform all arithmetic operations using a clear C program.

BeginnerArithmetic operatorsDivisionModulus

PROBLEM UNDERSTANDING

Input and expected output

Sample input
20 6
Sample output
Sum = 26
Difference = 14
Product = 120
Quotient = 3.33
Remainder = 2

COMPLETE C PROGRAM

Complete C implementation

all-arithmetic-operations.c
Open in compiler
#include <stdio.h>

int main(void)
{
    int first, second;

    printf("Enter two integers: ");
    scanf("%d %d", &first, &second);
    printf("Sum = %d\nDifference = %d\nProduct = %d\n", first + second, first - second, first * second);
    if (second != 0) {
        printf("Quotient = %.2f\nRemainder = %d\n", (double) first / second, first % second);
    } else {
        printf("Division and remainder are undefined for zero.\n");
    }
    return 0;
}

GUIDED CODE TOUR • NOT LIVE EXECUTION

Study the program line by line

Use the real compiler button above to run and debug with different inputs.

CURRENT STEP

Select Start to walk through the important lines.

SELECTED LINE

No line selected

EXPECTED OUTPUT FOR THE SAMPLE

Sum = 26
Difference = 14
Product = 120
Quotient = 3.33
Remainder = 2
0%Step 0 of 0

PROGRAM EXPLANATION

Algorithm and explanation

  1. Read the required input values.
  2. Apply each arithmetic operator and guard division against a zero divisor.
  3. Display the computed result.

Apply each arithmetic operator and guard division against a zero divisor.

EFFICIENCY

Time and space complexity

Time complexity

O(1)

Auxiliary space

O(1)

DEBUGGING CHECKLIST

Common mistakes

Check this

Use the correct format specifier for every variable.

Check this

Initialize variables before using their values.

Check this

Check braces, semicolons and input order carefully.

Try it yourself

Practice: Run the program with the sample input, predict its output, and then test one boundary case of your own.