Home / Programs / Program to find subtraction of two numbers using c programming language
Programming Example

Program to find subtraction of two numbers using c programming language

👁 5,621 Views
💻 Practical Program
📘 Step by Step Learning

In this example, the user is asked to enter two integers. Then, we we will subtract from one variable from another and displayed on the screen.

Flow chart

Program to find subtraction of two numbers
Figure:

To understand this example, you should have the knowledge of the following C programming topics:

  • C Data Types
  • C Variables, Constants and Literals
  • C Input Output (I/O)
  • C Programming Operators

Program Code

#include"stdio.h" 
 void main()
	{
        // variable declaration
	int num1, num2, subResult; 

	printf("Enter two no: ");
 	scanf("%d%d",&num1,&num2);
	subResult = num1 - num2;

       // Print result
       printf("subtraction result =%d \n", subResult);
    
}

Output

Enter two no: 6 3
sum=3
Press any key to continue . . .

Explanation

Algorithm:

  • Step 1: Start
  • Step 2: Declare variable number 1, number 2 and subResult
  • Step 3: Read Variable number 1, number 2
  • Step 4: Perform operation (subResult = num1 - num2)
  • Step 5: Print subResult variable
  • Step 7: Stop

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.