Write a Program to calculate Addition, Subtraction, Multiplication and Division of given two numbers using arithmetic operator

Here is a C program that calculates addition, subtraction, multiplication, and division of two given numbers using arithmetic operators:

				
					#include <stdio.h>

int main() {
    int num1, num2;
    int result_add, result_sub, result_mul, result_div;

    printf("Enter two numbers: ");
    scanf("%d %d", &num1, &num2);

    result_add = num1 + num2;
    result_sub = num1 - num2;
    result_mul = num1 * num2;
    result_div = num1 / num2;

    printf("%d + %d = %d\n", num1, num2, result_add);
    printf("%d - %d = %d\n", num1, num2, result_sub);
    printf("%d * %d = %d\n", num1, num2, result_mul);
    printf("%d / %d = %d\n", num1, num2, result_div);

    return 0;
}

				
			

Output

C Program to Perform Addition, Subtraction, Multiplication and Division

Explanation:

  • The program prompts the user to enter two numbers.
  • The user input is read using scanf and stored in the variables num1 and num2.
  • Four variables result_add, result_sub, result_mul, and result_div are declared to store the results of the addition, subtraction, multiplication, and division operations, respectively.
  • The arithmetic operations are performed using the arithmetic operators +, -, *, and /.
  • The results are displayed using printf. Note that %d is used as the format specifier for integers.

.