In this article, I will tell you a C program for the addition of two integers entered by the user. It is a dynamic program which means you can take any value. Before you go to the program firstly you have to know some basics of C language which will help you to understand the program. Below are two basic videos on C (in Hindi) watch both of them then go through the program part.
Part 1
Part 2
Addition of two integer
- #include<stdio.h>
//header file
- main() //main funcion
- {
- int
num1
,num2
,num3
;//three variables
- printf(“enter two numbers”);
- scanf(“
%d%d
“, &num1
, &num2
);//stored two value
-
num3 = num1+num2;
- printf(“The sum is = %d”,
num3
);//print sum
- }
Explanation
1. #include<stdio.h>
this is the header file and this is our main()
function.
2. int num1, num2, num3;
here are three variables. In num1 and num2 we store our two integers values. In num3 we will store the sum of num1 and num2.
3. printf("enter two numbers");
this is a normal print statement that will print the message “enter two numbers”.
4. scanf("%d%d", &num1, &num2);
here we have stored two integers on the address of num1 and num2.
5.num3 = num1+num2;
the sum is stored in the num3 variable.
6. printf("The sum is = %d", num3);
this statement will print the message “The sum is = (replace the value of num 3 with %d)”.