Write a c program to subtract two numbers.

Introduction: In the world of programming, C is a popular and powerful language known for its efficiency and flexibility. In this article, we will guide you through the process of writing a C program to subtract two numbers. This program will showcase the fundamental syntax and logic required to perform subtraction operations in C. So, let’s dive in and get started!

Step 1: Setting up the Development Environment: Before we begin writing the program, it’s important to have a suitable development environment. You will need a text editor (such as Notepad++, Sublime Text, or Visual Studio Code) and a C compiler (such as GCC or Clang) installed on your system. Ensure that the compiler is properly configured and ready for use.

Step 2: Creating a New C Program: Open your preferred text editor and create a new file. Save it with a suitable name, such as “subtract.c” or any other name of your choice. The “.c” extension indicates that this is a C programming file.

Step 3: Writing the Program: Let’s start writing the program code. Begin by including the necessary header files. In this case, we need the “stdio.h” header file, which provides input and output functions.

Get two integer numbers, subtract both the integers and display the difference

Sample Input 1:

6 5

Sample Output 1:


Sample Input 2:

65 4

Sample Output 2:


Program or Solution

int main()
	int num1,num2,diff;
	printf("Enter two numbers:");
	scanf("%d %d",&amp;num1,&amp;num2);
	printf("\nDifference is : %d",diff);
	return  0;

Out Put

Enter two numbers: 6 5 Difference is : 1


Congratulations! You have successfully written a C program to subtract two numbers. This program serves as a basic example to understand the structure and syntax of C programming. Feel free to explore more complex operations and expand your knowledge. Happy coding!

Leave a Comment