- Check here for printing an integer in c
- We have 4 basic data types in c programming language
- int, char, float and double
- For storing numbers or integers we will use int data type.
- Lets see an example program sum of two integers in c programming language.
- To add two integers we need two int type variables and third variable to store result of sum of two integers.
- Its a basic level example program for beginners to understand integer data types
Write a C program to add two integers / find sum of two integers in c
- #include<stdio.h>
- // c program to print integer using %d
- // c print integer
- //www.instanceofjava.com
- int main()
- {
- //declare an integer variable
- int number1, number2, sumOfTwoIntegers;
- // read input from user using scanf
- printf ("Enter any two integers: ");
- scanf (" %d%d", &number1,&number2);
- //sum of two integers in c
- sumOfTwoIntegers=number1+number2;
- //print the same number using %d
- printf("Sum of two integers : %d", sumOfTwoIntegers);
- getch();
- }
Output:
- Enter any two integers:
- 10
- 20
- Sum of two integers : 30
No comments