•  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

sum of two integers in c


Write a C program to add two integers / find sum of two integers in c

  1. #include<stdio.h>
  2. // c program to print integer using %d
  3. // c print integer
  4. //www.instanceofjava.com
  5. int main()
  6. {
  7.             //declare an integer variable 
  8. int number1, number2, sumOfTwoIntegers;
  9.             // read input from user using scanf
  10. printf ("Enter any two integers: ");
  11. scanf (" %d%d", &number1,&number2);
  12. //sum of two integers in c
  13. sumOfTwoIntegers=number1+number2;
  14.    //print the same number using %d
  15. printf("Sum of two integers : %d", sumOfTwoIntegers);
  16. getch();
  17. }
Output:
  1. Enter any two integers:
  2. 10
  3. 20
  4. Sum of two integers : 30

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu