English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C Program to Add Two Integers

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.

Program adds two integers

#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);

Comprehensive Collection of C Programming Examples