Write a Program to Add, Subtract, Multiply, and Divide Two Numbers in C
In this tutorial, we are going to see how to write a program to add, subtract, multiply, and divide two numbers in C. To perform addition, subtraction, multiplication, and division of any two numbers in C programming, you must ask the user to enter these two numbers first, and then apply the operator to these two numbers to perform the mathematical operations.
Write a Program to Add, Subtract, Multiply, and Divide Two Numbers in C
#include <stdio.h>
int main()
{
int nbr1, nbr2, addition, subtraction, multiplication;
float division;
printf("Enter two numbers: \n");
scanf("%d%d", &nbr1, &nbr2);
addition = nbr1 + nbr2;
subtraction = nbr1 - nbr2;
multiplication = nbr1 * nbr2;
division = nbr1 / (float)nbr2; //type casting
printf("Addition = %d\n", addition);
printf("Subtraction = %d\n", subtraction);
printf("Multiplication = %d\n", multiplication);
printf("Division = %.2f\n", division);
return 0;
}
Output:
Enter two numbers: 4 2 Addition = 6 Subtraction = 2 Multiplication = 8 Division = 2.00




