Types of functions in C programing language

 Types of function 

Types of function 

program:- add two number with all categories

i) Functions with no arguments and no return values.

Syntax:

function_name()
{
valid C Code;
}

code-
#include<stdio.h>
void sum()
{
int x,y,z;
printf("Enter two no's ");
scanf("%d%d",&x,&y);
z=x+y;
printf("sum of %d & %d =%d",x,y,z);
}
void main()
{
sum();
}

Output-
Enter two no's 95
36
sum of 95 & 36 =131
--------------------------------


ii) Functions with arguments and no return values 

Syntax:
function_name(argument1,argument2,- - - - - - -,argument n)
{
Valid C Code;
}

Code:
#include<stdio.h>
void sum(int x,int y)
{
int z;
z=x+y;
printf("sum of %d & %d =%d",x,y,z);
}
void main()
{
int x,y;
printf("Enter two no's");
scanf("%d %d",&x,&y);
sum(x,y);
}

Output:

Enter two no's12
32
sum of 12 & 32 =44
--------------------------------

iii) Functions with arguments and return values 

Syntax:

Data_typefunction_name(argument 1,argument 2,- - - - - ,argument n)
{
Valid C Code;
return(value);
}

Code:
#include<stdio.h>
int  sum(int x,int y)
{
int z;
z=x+y;
return z;
}
void main()
{
int x,y,c;
printf("Enter two no's");
scanf("%d %d",&x,&y);
c=sum(x,y);
printf("sum of %d & %d =%d",x,y,c);
}

Output:-
Enter two no's45
23
sum of 45 & 23 =68
--------------------------------


iv) Function with no arguments but with return values 

Syntax:

Data_typefunction_name()
{
valid C Code;
return(value);
}

Code:-
#include<stdio.h>
int  sum()
{
int z,x,y;
printf("Enter two no's");
scanf("%d %d",&x,&y);
z=x+y;
return z;
}
void main()
{
int c;
c=sum();
printf("sum=%d",c);
}

Output:
Enter two no's45
69
sum=114
--------------------------------




















Comments

Popular posts from this blog

CYBER SECURITY & CRACKING PASSWORDS

"The Dark Side of Social Media: How It Fuels Digital Addiction and Impacts Mental Health"

Online Platforms to Learn Coding