FUNCTIONS

C++ PROGRAM

// PROGRAM FOR LEARNING BASIC FUNCTIONS
//CODING ACCORDING TO TURBO C++ AND DOS-BOX FORMAT
//FOR OTHER PLATFORM CODE WILL BE SAME ONLY CERTAIN KEYWORDS WILL BE CHANGED

SOURCE CODE :

#include<iostream.h>
#include<conio.h>
void add () // no argument and no return-type
{
int n1,n2,c;
cout<<“\n Enter the 1st Element : “;
cin>>n1;
cout<<“\n Enter the 2nd Element : “;
cin>>n2;
c=n1+n2;
cout<<“\n SUM : “<<c;
}
void add(int p,intq) // with argument and no return-type
{
int c;
cout<<“\n Enter the 1st Element : “;
cin>>p;
cout<<“\n Enter the 2nd Element : “;
cin>>q;
c=p+q;
cout<<“\n SUM : “<<c;

}
int add(int p,intq)                                                             // with argument and with return-type
{
int c;
cout<<“\n Enter the 1st Element : “;
cin>>p;
cout<<“\n Enter the 2nd Element : “;
cin>>q;
c=p+q;
return c
}
int add() // no argument and with return-type
{
int n1,n2,c;
cout<<“\n Enter the 1st Element : “;
cin>>n1;
cout<<“\n Enter the 2nd Element : “;
cin>>n2;
c=n1+n2;
return c;

}
void main()
{

clrscr();

int a,b,c,d;

c=add(a,b); // calling for with arguement and with return value

add(a,b); // calling for with arguement and no return value

d=add(); // calling for no aruguement and with return value

add(); // calling for no aruguement and no return value

getch();
}

Advertisements