C Program to Add Two Numbers
Here’s a C program that adds two integers:
#include
int main() {
// Declare variables.
int num1, num2, sum;
// Get the two integers from the user.
printf("Enter the first integer: ");
scanf("%d", &num1);
printf("Enter the second integer: ");
scanf("%d", &num2);
// Add the two integers and store the result in sum.
sum = num1 + num2;
// Print the sum.
printf("The sum of the two integers is %d\n", sum);
return 0;
}
Output

In this program, we declare three integer variables:
num1
to store the first integer,num2
to store the second integer, andsum
to store the sum of the two integers.The user is prompted to enter the first integer using the
printf
function, and thescanf
function is used to read the input and store it in thenum1
variable.Similarly, the user is prompted to enter the second integer, which is then stored in the
num2
variable usingscanf
.To add the two integers, we simply use the
+
operator and assign the result to thesum
variable.Finally, the program displays the sum of the two integers using
printf
with the%d
format specifier for integers.