Sie sind auf Seite 1von 5

Function - It is a predefined unit of code to achieve a desired goal.

These are of two types:

a) Predefined - Already declared and defined in the language compiler we are going
to use, we need to include the associated header file for its use in a program

b) User Defined - These need to be declared outside a program in which we are going
to use and then in the main program we need to call the name of the function along
with the values to use it.

#include<iostream.h>
void main()
{
int a=10,b=20,c=0;
c=a+b;
cout<<"Result is="<<c;
}

#include<iostream.h>
void main()
{
int add(int,int); Function prototype
int a=10,b=20,c=0;
c=add(a,b); Function Call, a and b are actual parameters or arguments
cout<<"Result is="<<c;
}

int add(int a,int b) Function Definition, a and b are formal parameters or


arguments
{
int c=0;
c=a+b;
return(c);
}

****************************************

#include<iostream.h>
void main()
{
int add(int,int); Function prototype
int a=10,b=20;
add(a,b); Function Call, a and b are actual parameters or arguments
}

int add(int a,int b) Function Definition, a and b are formal parameters or


arguments
{
int c=0;
c=a+b;
cout<<"Result is="<<c;
return 0;
}

****************************************
#include<iostream.h>
void main()
{
void add(int,int); Function prototype
int a=10,b=20;
add(a,b); Function Call, a and b are actual parameters or arguments
}

void add(int a,int b) Function Definition, a and b are formal parameters or


arguments
{
int c=0;
c=a+b;
cout<<"Result is="<<c;
}
****************************************

#include<iostream.h>
void main()
{
int add(); Function prototype
add(); Function Call
}

int add() Function Definition


{
int a=10,b=20,c=0;
c=a+b;
cout<<"Result is="<<c;
return 0;
}
****************************************

#include<iostream.h>
void main()
{
int add(); Function prototype
int c=0;
c=add(); Function Call
cout<<"Result is="<<c;
}

int add() Function Definition


{
int a=10,b=20,c=0;
c=a+b;
return(c);
}
****************************************

#include<iostream.h>
void main()
{
int addi(int,int); Function prototype
int subt(int,int); Function prototype
int mult(int,int); Function prototype
int divi(int,int); Function prototype
int a,b,res=0;
cout<<"Enter a and b";
cin>>a>>b;
res=addi(a,b); Function Call, a and b are actual parameters or
arguments
cout<<"Addition is="<<res;
res=subt(a,b); Function Call, a and b are actual parameters or
arguments
cout<<"Substraction is="<<res;
res=mult(a,b); Function Call, a and b are actual parameters or
arguments
cout<<"Multiplication is="<<res;
res=divi(a,b); Function Call, a and b are actual parameters or
arguments
cout<<"Division is="<<res;
}

int addi(int a,int b) Function Definition, a and b are formal parameters or


arguments
{
int c=0;
c=a+b;
return(c);
}

int subt(int a,int b) Function Definition, a and b are formal parameters or


arguments
{
int c=0;
c=a-b;
return(c);
}

int mult(int a,int b) Function Definition, a and b are formal parameters or


arguments
{
int c=0;
c=a*b;
return(c);
}

int divi(int a,int b) Function Definition, a and b are formal parameters or


arguments
{
int c=0;
c=a/b;
return(c);
}

********************************************
#include<iostream.h>
void main()
{
void big(int,int); Function prototype
int a,b;
cout<<"Enter a and b";
cin>>a>>b;
big(a,b); Function Call, a and b are actual parameters or arguments
}

void big(int a,int b) Function Definition, a and b are formal parameters or


arguments
{
if(a>b)
{
cout<<a;
}
else
{
cout<<b;
}
}

****************************************
#include<iostream.h>
void main()
{
int big(int,int); Function prototype
int a,b,c=0;
cout<<"Enter a and b";
cin>>a>>b;
c=big(a,b); Function Call, a and b are actual parameters or arguments
cout<<"Bigger is="<<c;
}

int big(int a,int b) Function Definition, a and b are formal parameters or


arguments
{
if(a>b)
{
return(a);
}
else
{
return(b);
}
}

*****************************************

#include<iostream.h>
void main()
{
int big(); Function prototype
c=big(); Function Call
cout<<"Bigger is="<<c;
}

int big() Function Definition, a and b are formal parameters or arguments


{
int a,b,c=0;
cout<<"Enter a and b";
cin>>a>>b;
if(a>b)
{
c=a;
}
else
{
c=b;
}
return(c);
}
*****************************************
#include<iostream.h>
void main()
{
void table(int); Function prototype
int n;
cout<<"Enter n";
cin>>n;
table(n); Function Call, a and b are actual parameters or arguments
}

void table(int n) Function Definition, a and b are formal parameters or arguments


{
int i;
for(i=1;i<=10;i++)
{
cout<<n*i<<endl;
}
}

Das könnte Ihnen auch gefallen