Addition of two numbers in c is very simple and easy program in c.
In this tutorial we are going to see very simple program to implement which is addition of two numbers in c.
Addition of two number in c is a basic program.
Concepts we require to know form c are –
How to add two numbers
We take 2 numbers input from user and add two numbers and store addition in third variable and print addition we got.
Number 1 = 10
Number 2 = 10
Sum = Number 1 + Number 2
Sum = 20
This is a simple way to perform addition of two numbers.
Algorithm for addition of two numbers in c
- Declare variables a , b , c
- Take input number from user a and b
- Perform addition of numbers c = a + b
- Print addition c
Now let’s see the program which implements the addition of two numbers program in c.
Program to add two numbers
int no1, no2, sum;
//take user input
printf(" \n Enter first number :");
printf ("\n Enter second number :");
sum = no1 + no2;
printf ("\n Addition of two numbers =%d",sum);
Program Explanation :-
1. First, start with declaring the preprocessor directives stdio.h
2. Write the main function where execution starts
3. Next, we declare variables we require
no1 => to store first number
no2 => to store second number
sum => to store addition of numbers
4. Next line we take user input no1 and no2 for taking the input we use stdio standard functions which are
printf(” \n Enter first number :”); => this function used to print the stream to the output screen so we printed the message which tell user to enter first number.
after this we write scanf(“%d”,&no1); => this function used to read the input which user enters and store it in variable so using this we read no1 from user.
For example :- if user enters 10 then 10 is stored in no1.
no1 = 10
5. Next two line also same for reading no2 .
no2 = 10
6. Now we have 2 numbers no1 = 10 and no2 = 10 , so we perform addition of that two number.
sum = no1 + no2 => this statement adds no1 and no2 values and store result in sum so we got sum = 20.
7. Now we got the addition of numbers in sum .so print addition
printf (“\n Addition of two numbers =%d”,sum);
8. This prints the addition.