Simple C Program to Display Addition of Two Integers
/ C program to display addition of two integers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10;
int b=10;
int sum;
clrscr();
sum=a+b;
printf("The addition of two numbers is:\t%d",sum);
}
Output:
The addition of two numbers is: 20
In above program the integer values are assigned to a and b variables with assignment = operator. In every execution of program the integer values will remain same because values are assigned to variables and hence result will be same.
Addition of Two Integers
// C program to display addition of two integers
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
int b;
int sum;
clrscr();
printf(" Enter first number:");
scanf("%d",&a);
printf(" \nEnter second number:");
scanf("%d",&b);
sum=a+b;
printf("The addition of two numbers is:\t%d",sum);
}
In following program the instruction to read two integers is given in one line.
// C program to display addition of two integers
#include<stdio.h>
#include<conio.h>
void
main()
{
int a;
int b;
int sum;
clrscr();
printf(" Enter two numbers:");
scanf("%d%d",&a,&b);
sum=a+b;
printf("The addition of two numbers is:\t%d",sum);
}
Output:
Enter
two numbers:3 4
The
addition of two numbers is: 7
In above program two variables are declared a and b which store integer type of data. sum variable is declared to store addition of two numbers.
Two integers are entered through keyboard and scanf() function is used to accept user input.scanf() function is input function. &a,&b is used to store two integers in a and b variables.
For addition of two numbers sum=a+b processing statement is used.
The sum is displayed with the help of printf() function.
0 टिप्पण्या
कृपया तुमच्या प्रियजनांना लेख शेअर करा आणि तुमचा अभिप्राय जरूर नोंदवा. 🙏 🙏