C LanguageProgramming

C Program For Addition Of Two Integers (Entered By The User)

addition of two numbers
Spread the love

In this article, I will tell you a C program for the addition of two integers entered by the user. It is a dynamic program which means you can take any value. Before you go to the program firstly you have to know some basics of C language which will help you to understand the program. Below are two basic videos on C (in Hindi) watch both of them then go through the program part.

Part 1
Part 2

Addition of two integer

  1. #include<stdio.h> //header file
  2. main() //main funcion
  3. {
  4. int num1, num2, num3; //three variables
  5. printf(“enter two numbers”);
  6. scanf(“%d%d“, &num1, &num2); //stored two value
  7. num3 = num1+num2;
  8. printf(“The sum is = %d”, num3); //print sum
  9. }

Explanation

1. #include<stdio.h> this is the header file and this is our main() function.

2. int num1, num2, num3; here are three variables. In num1 and num2 we store our two integers values. In num3 we will store the sum of num1 and num2.

3. printf("enter two numbers"); this is a normal print statement that will print the message “enter two numbers”.

4. scanf("%d%d", &num1, &num2); here we have stored two integers on the address of num1 and num2.

5.num3 = num1+num2; the sum is stored in the num3 variable.

6. printf("The sum is = %d", num3); this statement will print the message “The sum is = (replace the value of num 3 with %d)”.


Spread the love
Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.