Syntax:
return type function name (argument list)
{
Body of the loop
}
Characteristics of a function :
1.Function declaration or proto type
2.Calling function sum();
3.Called function can be divided into 4 categories:
(i) Function with no return and no argument
(ii) Function with no return and with argument
(iii) Function with return and with no argument
(iv) Function with return and with argument
{
Body of the loop
}
Characteristics of a function :
1.Function declaration or proto type
2.Calling function sum();
3.Called function can be divided into 4 categories:
(i) Function with no return and no argument
(ii) Function with no return and with argument
(iii) Function with return and with no argument
(iv) Function with return and with argument
Note:
1. The parameters which are used under calling functions are called Actual parameters.
2. The parameters which are used under called functions are called Dummy parameters.
2. The parameters which are used under called functions are called Dummy parameters.
/*Function with no return and no argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void sum(void); /*Function Declaration or Proto Type*/
void main()
{
clrscr();
sum(); /*Calling Function*/
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void sum(void); /*Function Declaration or Proto Type*/
void main()
{
clrscr();
sum(); /*Calling Function*/
getch();
}
Void sum(void) /*called function*/
{
int a,b,c;
printf(“enter a,b values:”);
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“sum is %d”,c);
}
/*Example2:Function with no return and no argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void mul(void); /*Function Declaration or Proto Type*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void mul(void); /*Function Declaration or Proto Type*/
void main()
{
clrscr();
mul(); /*calling function*/
getch();
}
{
clrscr();
mul(); /*calling function*/
getch();
}
void mul(void) /*called function*/
{
int a,b,c;
printf(“enter a,b values:”);
scanf(“%d%d”,&a,&b);
c=a*b;
printf(“multiplication is %d”,c);
}
output:/* Function with no return and with argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void sum(int,int); /*Function Declaration or Proto Type*/
void main()
{
int a,b;
clrscr();
printf(“enter a,b values:”);
scanf(“%d%d”,&a,&b);
sum(a,b); /*calling function*/ // actual parameters
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void sum(int,int); /*Function Declaration or Proto Type*/
void main()
{
int a,b;
clrscr();
printf(“enter a,b values:”);
scanf(“%d%d”,&a,&b);
sum(a,b); /*calling function*/ // actual parameters
getch();
}
void sum(int p,intq) *called function*/ // dummy parameters
{
int r;
r=p+q;
printf(“sum is %d”,r);
}
{
int r;
r=p+q;
printf(“sum is %d”,r);
}
/* Example 2:Function with no return and with argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void mul(int,int); /*Function Declaration or Proto Type*/
void main()
{
int a,b;
clrscr();
printf(“enter a,b values:”);
scanf(“%d%d “,&a,&b);
mul(a,b); /*calling function*/
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
void mul(int,int); /*Function Declaration or Proto Type*/
void main()
{
int a,b;
clrscr();
printf(“enter a,b values:”);
scanf(“%d%d “,&a,&b);
mul(a,b); /*calling function*/
getch();
}
void mul(int p,intq) /*called function*/
{
int r;
r=p*q;
printf(“multiplication is %d”,r);
}
output:
/* Function with return and with no argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int sum(void); /*Function Declaration or Proto Type*/
void main()
{
int c;
clrscr();
c=sum(); /*calling function*/
printf(“sum is %d”,c);
getch();
}
int sum(void) /* called function*/
{
int p,q,r;
printf(“enter p,q values:”);
scanf(“%d%d”,&p,&q);
r=p+q;
return r;
}
/* Function with return and with no argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int sum(void); /*Function Declaration or Proto Type*/
void main()
{
int c;
clrscr();
c=sum(); /*calling function*/
printf(“sum is %d”,c);
getch();
}
int sum(void) /* called function*/
{
int p,q,r;
printf(“enter p,q values:”);
scanf(“%d%d”,&p,&q);
r=p+q;
return r;
}
/* Example2:Function with return and with no argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int mul(void); /*Function Declaration or Proto Type*/
void main()
{
int c;
clrscr();
c=mul(); /*calling function*/
printf(“multiplication is %d”,c);
getch();
}
#include<conio.h>
#include<string.h>
#include<math.h>
int mul(void); /*Function Declaration or Proto Type*/
void main()
{
int c;
clrscr();
c=mul(); /*calling function*/
printf(“multiplication is %d”,c);
getch();
}
int mul(void) /*called function*/
{
int p,q,r;
printf(“enter p,q values”);
scanf(“%d%d”,&p,&q);
r=p*q;
return r;
}
output:
{
int p,q,r;
printf(“enter p,q values”);
scanf(“%d%d”,&p,&q);
r=p*q;
return r;
}
output:
/*Function with return and with argument*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
int sum(int,int); /*Function Declaration or Proto Type*/
void main()
{
int a,b,c;
clrscr();
printf(“enter a,b values”);
scanf(“%d%d”,&a,&b);
c=sum(a,b); /*calling function*/ // actual parameters
printf(“sum is %d “,c);
getch();
}
int sum (int p,int q) /*called function*/ // dummy parameters
{
int z;
z=p+q;
return z;
}
#include<conio.h>
#include<math.h>
#include<string.h>
int sum(int,int); /*Function Declaration or Proto Type*/
void main()
{
int a,b,c;
clrscr();
printf(“enter a,b values”);
scanf(“%d%d”,&a,&b);
c=sum(a,b); /*calling function*/ // actual parameters
printf(“sum is %d “,c);
getch();
}
int sum (int p,int q) /*called function*/ // dummy parameters
{
int z;
z=p+q;
return z;
}
/*Example 2:Function with return and with argument*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int mul(int,int); /*Function Declaration or Proto Type*/
void main()
{
int a,b,c;
clrscr();
printf(“enter a,b values”);
scanf(“%d%d”,&a,&b);
c=mul(a,b);
printf(“multiplication is %d “,c);
getch();
}
int mul(int p,int q)
{
int z;
z=p+q;
return z;
}
#include<conio.h>
#include<string.h>
#include<math.h>
int mul(int,int); /*Function Declaration or Proto Type*/
void main()
{
int a,b,c;
clrscr();
printf(“enter a,b values”);
scanf(“%d%d”,&a,&b);
c=mul(a,b);
printf(“multiplication is %d “,c);
getch();
}
int mul(int p,int q)
{
int z;
z=p+q;
return z;
}
No comments:
Post a Comment