Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Sum of two integers in c

  •  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

  1. #include
  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


This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

Sum of two integers in c

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×