C Program to Add Two Integers
In this example, we will learn to get two integer as user input then add them and print the output on the screen.
Remainder :
To understand this example, you should have the knowledge of the following C programming topics:
Program to Add Two Integers
#include <stdio.h>
int main() {
int num1, num2, sum;
printf("Enter two number : ");
scanf("%d %d", &num1, &num2);
sum = num1 + num2;
printf("The sum of %d and %d is %d", num1, num2, sum);
return 0;
}
Output
Enter two number : 34 23
The sum of 34 and 23 is 57
Working of the above program
- First we declare three integer variables num1, num2 and sum, in which num1, num2 used to store integers and sum to store the sum of both integers .
int num1, num2, sum;
printf("Enter two number : ");
scanf("%d %d", &num1, &num2);
sum = num1 + num2;
printf("The sum of %d and %d is %d", num1, num2, sum);