Home / Programs / C program to add two numbers
Programming Example

C program to add two numbers

👁 53,784 Views
💻 Practical Program
📘 Step by Step Learning
C program to add two numbers

Information & Algorithm

In this program we will add two numbers using c programming language. First we will take two variable num1 and num2 to store the value. Then using the arithmetic operator (+) we will add them then we will store the result in sum variable. At last we will print the sum variable to see the result. 

Flow chart

C program to add two numbers

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 first number: ");
    scanf("%d", &num1);
    printf("Enter second number:");
    scanf("%d", &num2);
     
    /* Adding both number is simple and fundamental */
    sum = num1 + num2;
     
    /* Prints the sum of two numbers */
    printf("Sum of %d and %d = %d \n", num1, num2, sum);
     
    return 0;
}

Output

Enter first number: 55
Enter second number:22
Sum of 55 and 22 = 77
Press any key to continue . . .

Explanation

Explanation

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.