C Exercises: Calculate the sum of the two integers
C Basic Declarations and Expressions: Exercise-9 with Solution
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:
C Programming Code Editor:
Previous: Write a C program to convert specified days into years, weeks and days.
Next: Write a C program that accepts two integers from the user and calculate the product of the two integers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/c-programming-exercises/basic-declarations-and-expressions/c-programming-basic-exercises-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics