English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Comprehensive Collection of C Programming Examples
In this example, the user is required to enter two integers. Then, calculate the sum of these two integers and display it on the screen.
#include <stdio.h> int main() { int number1, number2, sum; printf("Enter two integers: "); scanf("%d %d", &number1Please enter the number2); //Calculate the sum sum = number1 + number2; printf("%d + %d = %d", number1, number2, sum); return 0; }
Output result
Enter two integers: 12 11 12 + 11 = 23
In this program, the user is required to enter two integers. These two integers are stored in the variable number1and number2.
printf("Enter two integers: "); scanf("%d %d", &number1Please enter the number2);
Then, use+The operator adds these two numbers and stores the result in the sum variable.
sum = number1 + number2;
Finally, the printf() function is used to display the sum of numbers.
printf("%d + %d = %d", number1, number2, sum);