c-program-to-add-two-numbers
In This c program, we are going to add two numbers, for example if we get two numbers 4 and 5 the program will output the result as 9 which equals to 4+5.
As said in the previous tutorial instead of declaring the values of the variables inside the program we will get the values by the user using scanf function in c to make the program general.

Read : How to use Scanf function in c program

C Program To Add Two Numbers Using Addition Operator

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,add;
clrscr();

printf("\n Enter Any Two Numbers To Add : ");
scanf("%d%d",&a,&b);

add=a+b;

printf("\n Addition = %d",add);

getch();
}

Output :


c-program-to-add-two-numbers-output








Watch the video below For Better Understanding of this program.

C Program For Dev C++ to Add Two Numbers

#include<stdio.h>
#include<conio.h>
 main()
{
 int a,b,add;
  
 printf("\n Enter Any Two Numbers To Add : ");
 scanf("%d%d",&a,&b); // get the values by user

 add=a+b; // addtion is performed and stored in "add"

 printf("\n Addition = %d",add); // display output

 getch();
 return 0;
 
}

Output : 
c-program-to-add-two-numbers-output





We can Also Perform the addition of two numbers using functions in C for that we will create a function named as 'add'(it is not necessary to name it as add you can call it whatever you like) define the function appropriately and call it from the main function as shown below : 

C program to add two numbers using function:

#include<stdio.h>
#include<conio.h>
int add(int a,int b); //function declaration

void main()
{
 int sum,x,y;
 clrscr();

 printf("\n Enter Any Two Numbers To Add : ");
 scanf("%d%d",&x,&y);

 sum=add(x,y); //calling the function

 printf("\n Addition = %d",sum);

 getch();

 }

 int add(int a, int b)  //definition of function
 {
  int c;

  c=a+b;

  return(c);
 }

We can also use pointers to perform this addition in C like below :

Add two numbers using pointers in C 

#include<stdio.h>
#include<conio.h>
void main()
{
 int *p1,*p2,a,b,add;
 clrscr();

 printf("\n Enter Any Two Numbers To Add : ");
 scanf("%d%d",&a,&b);

 p1=&a;
 p2=&b;

 add= *p1 + *p2;

 printf("\n Addition = %d",add);

 getch();

}

In this way, we can add two numbers in C using functions and pointers.