A directory of Objective Type Questions covering all the Computer Science subjects.
Here you can access and discuss Multiple choice questions and answers for various competitive exams and interviews.
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 */
#include<stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: \n");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
return(0);
}
Program Output
Case 1:
Enter two numbers:
-56
28
Sum : -28
Case 2:
Enter two numbers:
125
789
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.