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.

This simple C program takes two integer numbers from the user and print their sum on the screen.

C program to add two integer numbers - Source code

#include<stdio.h>
int main() {
int a, b, sum;
printf("\nEnter the two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum of %d and %d is %d", a,b,sum);
return(0);
}

Program Output

Case 1:
Enter the two numbers: 456
26
Sum of 456 and 26 is 482
Case 2:
Enter the two numbers: 721
457
Sum of 721 and 457 is 1178

Program Explanation

1. Three integers variables a, b and sum are declared.
2. User is asked to input two integers to calculate the sum. Entered numbers are stored in a and b variables using the scanf function.
3. Sum of a and b is obtained using arithmetic Addition(+) operator.