Program: Add Two Numbers
#include <stdio.h>
int main() {
int num1 = 5;
int num2 = 7;
int sum;
sum = num1 + num2;
printf("The sum of %d and %d is: %d", num1, num2, sum);
return 0;
}
Explanation of Each Part
1. #include <stdio.h>
- This line includes stdio header file.
- This line tells the computer:
“I want to use printing functions likeprintf
.”
2. int main() {
- This is where the program starts running.
3. int num1 = 5;
- This makes a number box called
num1
. - We put the number 5 into that box.
4. int num2 = 7;
- This makes another number box called
num2
. - We put the number 7 into it.
5. int sum;
- This is a third box, called
sum
. - We will use it to store the result.
6. sum = num1 + num2;
- We add the first and second numbers.
- Then we put the answer into the
sum
box.
7. printf("The sum of %d and %d is: %d", num1, num2, sum);
- This prints the numbers and the answer.
%d
means “print a number.”
8. return 0;
- This tells the computer:
“The program finished without problems.”
Final Output
When you run the program, it shows:
The sum of 5 and 7 is: 12