C PROGRAM TO ADD TWO
INTEGERS
In this program, user
is asked to enter two integers and this program will add these two integers and
display it.
SOURCE
CODE
/*C programming source
code to add and display the sum of two integers entered by user */
#include <stdio.h>
int main( )
{
int num1, num2, sum;
printf("Enter two integers: ");
scanf("%d %d",&num1,&num2);
/* Stores the two integer entered by user in variable num1 and num2 */
sum=num1+num2; /* Performs addition and stores it in
variable sum */
printf("Sum: %d",sum); /* Displays sum */
return 0;
}
OUTPUT
1:
Enter
two integers: 12
11
Sum:
23
Explanation
: In this program, user is asked to enter two integers. The two integers entered
by user will be stored in variables num1 and num2 respectively. This is done
using scanf( ) function. Then, + operator is used for adding variables num1 and
num2 and this value is assigned to variable sum.
Finally, the sum is
displayed and program is terminated.
No comments:
Post a Comment