C program to add two numbers

Problem Description

Addition program is one of the simplest program in any programming language. This C program takes two integer numbers from the user and display their sum.

C program to add two numbers - Source code
  /* C program to add two numbers */


int main() {
   int a, b, sum;

   printf("Enter two numbers: \n");
   scanf("%d %d", &a, &b);

   sum = a + b;

   printf("Sum : %d", sum);


Program Output

Case 1:

Enter two numbers:
Sum : -28

Case 2:

Enter two numbers:
Sum : 914

Program Explanation

1. This program declares three integer variables a,b and sum.

2. Value of variables a and b variables is accepted from the user and their sum is stored in the sum variable.

3. Value of the variable sum is printed using the printf function.