4 types to define a function in c language.
■ 1->
without return type and without argument
#include<stdio.h>
#include<conio.h>
void add(void);
void main()
{
add();
}
void add(void)
{
int a,b;
printf("enter two number=");
scanf("%d%d",&a,&b);
printf("the sum of two numbers is =%d",(a+b));
}
■》Output->
enter two number=
3
4
the sum of two numbers is = 7
■2->
without return type and with argument
#include<stdio.h>
#include<conio.h>
void add(int ,int);
void main()
{
int a,b;
printf("enter two number=");
scanf("%d%d",&a,&b);
add(a,b);
}
void add(int a,int b)
{
printf("the sum of two numbers is =%d",(a+b));
}
■》Output->
enter two number=
4
3
the sum of two numbers is =7
■ 3->
with return type and withoit argument
#include<stdio.h>
#include<conio.h>
int add(void);
void main()
{
printf("the sum of two numbers is =%d",add());
}
int add(void)
{
int a,b;
printf("enter two number=");
scanf("%d%d",&a,&b);
return (a+b);
}
■》Output->
enter two numbers=
4
6
the sum of two numbers is =10
■ 4->
with return type and with argument
#include<stdio.h>
#include<conio.h>
int add(int ,int);
void main()
{
int a,b;
printf("enter two numbers=");
scanf("%d%d",&a,&b);
printf("the sum of two numbers is =%d",add(a,b));
}
int add(int a, int b)
{
return (a+b);
}
■》Output->
enter two number=
4
5
the sum of two numbers is =9
Comments
Post a Comment