C Program for Subtraction of Two Numbers

C Program for Subtraction of Two Numbers – Subtraction is a fundamental arithmetic operation that involves finding the difference between two numerical values. In computer programming, subtraction can be efficiently executed using various programming languages, including the popular language, C. In this article, we’ll explore a simple C program that performs subtraction between two numbers.

C Program for Subtraction

Subtraction, as an arithmetic operation, involves taking away one quantity from another to find the difference. In C programming, this operation can be performed using the subtraction operator (-). The program will prompt the user to enter two numbers and then subtract the second number from the first to obtain the result.

C Program for Subtraction

Let’s dive into the C program that demonstrates the subtraction of two numbers:

Output

C Program for Subtraction

C Program for Subtraction Explanation

  • This program starts by including the necessary header file stdio.h, which provides input and output functionalities. Then, it defines the main() function where the actual execution begins.
  • The program declares three integer variables: num1, num2, and result to store the two input numbers and the subtraction result, respectively.
  • The user is prompted to enter the first number using printf() and scanf() functions, which respectively display the message and read the input from the user.
  • Similarly, the program prompts for the second number and reads it using scanf().
  • The subtraction operation result = num1 - num2; calculates the difference between num1 and num2, storing the result in the result variable.
  • Finally, the program prints the result of the subtraction using printf() by displaying the equation and the computed result.

Happy Coding

See Also

Leave a Comment