Calculate sum of two integers
Calculate sum of two integers
Write a C program that accepts two integers from the user and calculates the sum of the two integers.
Pictorial Presentation:
C Code:
#include <stdio.h>
int main()
{
int x, y, sum; // Declare variables for two integers and their sum
// Prompt user for input and store in 'x'
printf("\nInput the first integer: ");
scanf("%d", &x);
// Prompt user for input and store in 'y'
printf("\nInput the second integer: ");
scanf("%d", &y);
sum = x + y; // Calculate the sum of 'x' and 'y'
// Print the sum
printf("\nSum of the above two integers = %d\n", sum);
return 0; // Indicate successful execution
}
Sample Output:
Input the first integer: 25 Input the second integer: 38 Sum of the above two integers = 63
Flowchart:
For more Practice: Solve these Related Problems:
- Write a C program to calculate the sum and difference of two integers provided by the user.
- Write a C program to compute the sum of three integers entered by the user.
- Write a C program to add two integers with input validation to ensure proper integer range and handle potential overflow.
- Write a C program to calculate the sum of two integers and then display the result in binary format.
Go to:
PREV : Convert days to years, weeks, and days.
NEXT : Calculate product of two integers.
C Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.