Home / Programs / C program to add two numbers in a single scanf function
🚀 Programming Example

C program to add two numbers in a single scanf function

👁 4,950 Views
💻 Practical Program
📘 Step Learning

In this program we will add two variable, we will take two variable in a single scanf function.

Flow chart

C program to add two numbers in a single scanf function

💻 Program Code

/**
 * Write a C program to input two numbers from user and calculate
 their sum. C program to add two numbers and display their sum as 
 output. How to add two numbers in C programming.
 */
 
#include"stdio.h"
 
int main()
{
    int num1, num2, sum;
     
    /*
     * Read two numbers from user
     */
    printf("Enter any two numbers : ");
    scanf("%d%d", &num1, &num2);
     
    sum = num1 + num2;
     
    /* Prints the sum of two numbers */
    printf("Sum of %d and %d = %d\n", num1, num2, sum);
     
    return 0;
} 
                        

🖥 Program Output

Enter any two numbers : 66
22
Sum of 66 and 22 = 88
Press any key to continue . . .
                            
📚 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.