Home / Programs / Program to find sum of two numbers using c programming language.
🚀 Programming Example

Program to find sum of two numbers using c programming language.

👁 12,090 Views
💻 Practical Program
📘 Step Learning

In this example, the user is asked to enter two integers. Then, the sum of these two integers is calculated and displayed on the screen.

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

Flow chart

C program to add two numbers
Figure:

💻 Program Code

#include"stdio.h"
 void main()
	{
	int num1, num2, sum; 
	printf("Enter two no: ");
 	scanf("%d%d",&num1,&num2);
	sum = num1 + num2;
        printf("sum=%d \n", sum );    
}
                        

🖥 Program Output

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

📘 Explanation

Algorithm:

  • Step 1: Start
  • Step 2: Declare variable number1, number2 and sum
  • Step 3: Read Variable number1, number2
  • Step 4: Perform operation (sum= number1+ number2)
  • Step 5: Print sum variable
  • Step 7: Stop

In this program, the user is asked to enter two integers. These two integers are stored in variables?number1?and?number2?respectively.

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

Then, these two numbers are added using the?+?operator, and the result is stored in the?sum?variable.

sum = num1 + num2;

Finally, the printf() function is used to display the sum of numbers.

printf("sum=%d \n", sum );
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.