C Program to Add Two Integers

Add Two Integers
(Last Updated On: September 2, 2018)

In this Program, you’ll learn how to Add Two Integers.

Add Two Integers; In this program, the user is asked to enter two integers. Then, the sum of those two integers is stored in a variable and displayed on the screen.

In C language we have data types for different types of data, for integers, it is int, for characters it is char, for floating point data it’s float and so on. For large integers, you can use long or long long data type.

To store integers which are larger than (2^18-1) which is the range of long long data type you may use strings. In the below program we store an integer in a string and then added it.

To understand this example of C Print Integer, you should have the knowledge of following C programming topics:

  1. Constants
  2. Variables
  3. Data Types
  4. Input-Output
  5. Arithmetic Operators

Program to Add Two Integers

#include <stdio.h>
int main()
	int firstNumber, secondNumber, sumOfTwoNumbers;
	printf(“Enter two integers: “);

	// Two integers entered by user is stored using scanf() function
	scanf(“%d %d”, &firstNumber, &secondNumber);

	// sum of two numbers in stored in variable sumOfTwoNumbers
	sumOfTwoNumbers = firstNumber + secondNumber;

	// Displays sum
	printf(“%d + %d = %d”, firstNumber, secondNumber, sumOfTwoNumbers);

	return 0;


Enter two integers: 12
12 + 11 = 23

C Program to Add Two Integers

In this program of Add Two Integers, the user is asked to enter two integers. Two integers entered by the user is stored in variables firstNumber and secondNumber respectively. This is done using scanf()function.

Then, variables firstNumber and secondNumber are added using + operator and the result is stored in sumOfTwoNumbers.

Finally, the sumofTwoNumbers is displayed on the screen using printf() function.

Ask your questions about how to Add Two Integers in C and clarify your/others doubts by commenting. Documentation.