If any function designed by the programmer is known as user defined function
Syntax returntype functionname(list of paramers/no parameters); //function Declaration
returntype functionname(list of paramers/no parameters) //function Body
{
....
....
....
....
}
in the above syntax first you declare the function.Ofter you declare the function body
These functions are classified into fallowing types
- Parametarized Function
- NoParametarized Function
Parametarized Function:If any function signature contains list of parameters is known as Parametarized Function.
Syntax returntype functionname(datatype variable1,datatype variable2,....); //function Declaration
returntype functionname(datatype variable1,datatype variable2,....) //function Body
{
....
....
....
....
}
NoParametarized Function:If any function signature does not contains list of parameters is known as NoParametarized Function.
Syntax returntype functionname(); //function Declaration
returntype functionname() //function Body
{
....
....
....
....
}
Based on the return type these functions are classified into following types
- No Returntype With NoParametarized Function
- No Returntype With Parametarized Function
- Returntype With NoParametarized Function
- Returntype With Parametarized Function
No Returntype With NoParametarized Function#include<stdio.h>
#include<conio.h>
void max();
void max()
{
int x,y;
printf("Enter x,y values");
scanf("%d%d",&x,&y);
if(x>y)
{
printf("x is max");
}
else
{
prinf("y is max");
}
};
void main()
{
clrscr();
max();
getch();
}
No Returntype With Parametarized Function#include<stdio.h>
#include<conio.h>
void max(int x,int y);
void max(int x,int y)
{
if(x>y)
{
printf("x is max");
}
else
{
prinf("y is max");
}
};
void main()
{
clrscr();
int x,y;
printf("Enter x,y values");
scanf("%d%d",&x,&y);
max(x,y);
getch();
}
Returntype With NoParametarized Function#include<stdio.h>
#include<conio.h>
int max();
int max()
{
int x,y;
printf("Enter x,y values");
scanf("%d%d",&x,&y);
if(x>y)
{
return x;
}
else
{
return y;
}
};
void main()
{
clrscr();
printf("%d",max());
getch();
}
Returntype With Parametarized Function#include<stdio.h>
#include<conio.h>
int max(int x,int y);
int max(int x,int y)
{
if(x>y)
{
return x;
}
else
{
return y;
}
};
void main()
{
clrscr();
int x,y;
printf("Enter x,y values");
scanf("%d%d",&x,&y);
printf("%d",max(x,y));
getch();
}