3. System Define function
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int num;
float r;
clrscr();
printf(“Enter any non”);
scanf(“%d”,&num);
r=sqrt(num);
printf(“root of %d is %f n”, num,r);
getch();
}
EXTRA
6. User Define Function
#include<stdio.h> Parameter and no return value
#include<conio.h>
void add(int, int);
void main()
{
int a,b;
clrscr();
printf(“Enter two numbern”);
scanf(“%d%d”,&a,&b);
printf(“Value of A =%dn”,a);
printf(“Value of B =%dn”,b);
add(a,b);
getch();
} no return
void add(int x, int y)
{ with Parameter
int z;
z=x+y;
printf(“Sum of two no = %dn”,z);
}
EXTRA
7. User Define Function
#include<stdio.h> Parameter and return value
#include<conio.h>
int add(int, int);
void main()
{
int a,b,c;
clrscr();
printf(“Enter two numbern”);
scanf(“%d%d”,&a,&b);
printf(“Value of A =%dn”,a);
printf(“Value of B =%dn”,b);
c=add(a,b);
printf(“Sum of two no = %dn”,c);
getch();
} with return
int add(int x, int y)
{ with parameter
int z;
z=x+y;
return z;
}
EXTRA
8. User Define Function
No #include<stdio.h> Parameter and no return value
#include<conio.h>
void disp();
void main()
{
clrscr();
disp();
getch();
} no return
void disp()
{ no parameter
int a,b,c;
printf(“Enter two numbern”);
scanf(“%d%d”,&a,&b);
printf(“Value of A =%dn”,a);
printf(“Value of B =%dn”,b);
c=a+b;
printf(“Sum of two no = %dn”,c);
getch();
}
EXTRA
9. User Define Function
No Parameter and return value
#include<stdio.h>
#include<conio.h>
int fact();
void main()
{
clrscr();
printf("Factorial %d",fact());
getch();
} with return
int fact()
{ no parameter
int n,f=1;
printf(" Enter any numbern");
scanf("%d",&n);
while(n>=1)
{
f=n*f;
n--;
}
return f;
}
EXTRA
10. User Define Function
Call by value method
#include<stdio.h>
#include<conio.h>
void disp (int , int);
void main()
{
int a,b;
clrscr();
printf(“Enter the Value of a & bn”);
scanf(“%d%d”,&a,&b);
printf(“Value of a before function %dn”,a);
printf(“Value of b before function %dn”,b);
disp(a,b);
printf(“value of a after function %dn”,a);
printf(“Value of b after function %dn”,b);
getch();
}
void disp(int a, int b)
{
a=a+10;
b=b+10;
printf(“Value of a inside function %dn”,a);
printf(“value of b inside function %dn”,b);
}
EXTRA
11. User Define Function
Call by reference method
#include<stdio.h>
#include<conio.h>
void disp (int &, int&);
void main()
{
int a,b;
clrscr();
printf(“Enter the Value of a & bn”);
scanf(“%d%d”,&a,&b);
printf(“Value of a before function %dn”,a);
printf(“Value of b before function %dn”,b);
disp(a,b);
printf(“value of a after function %dn”,a);
printf(“Value of b after function %dn”,b);
getch();
}
void disp(int &a, int &b)
{
a=a+10;
b=b+10;
printf(“Value of a inside function %dn”,a);
printf(“value of b inside function %dn”,b);
}
EXTRA