Adding Two Numbers in C Programming
- printf()function is used to display and print the string under the quotation to the screen.
- scanf() function is used to take input from the user.
- Here %d indicates that we are reading decimal/integer type
- The user is asked to enter two integers.
- These two integers are stored in variables number1 and number2.
- These two numbers are added using the + operator.
- The result is stored in the sum variable.
- The sum variable is displayed as output to the screen using printf() function
Source Code
#include <stdio.h>
#include <conio.h>
int main()
{
int number1, number2, sum;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
sum = number1 + number2;
printf("%d + %d = %d", number1, number2, sum);
return 0;
}
To download raw file
Click Here
Output
Enter two integers: 10 20
10+20=30