Write a program that takes two integers as input (one per line) and prints their sum as output.
For example,
For the input provided as follows:
2
3
The output of the program will be:
5
Answers
Answer:
include <stdio.h>
int main() {
int number1, number2, sum;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
// calculating sum
sum = number1 + number2;
printf("%d + %d = %d", number1, number2, sum);
return 0;
}
Output
Enter two integers: 12
11
12 + 11 = 23
In this program, the user is asked to enter two integers. These two integers are stored in variables number1 and number2 respectively.
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
Then, these two numbers are added using the + operator, and the result is stored in the sum variable.
sum = number1 + number2;
Adding two integers in C programming
Add Two Numbers
Finally, the printf() function is used to display the sum of numbers.
printf("%d + %d = %d", number1, number2, sum);
Answer:
the python program for the given question is as follows.
Explanation:
num1 = int(input("enter the first number"))
num2 = int(input("enter the second number"))
print(num1 + num2)
hope it helps