SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
User defined functions in C
Definition
 A set of statements working together with common

goal is known as function.
 Also known as subprograms which are used to
compute a value or perform a specific task.
 They can’t run independently and are always called by
the main() program or by some other function.
Categories of functions
Library functions
User-Defined functions
Library functions
These are also known as Pre defined functions.
Ex.
scanf(), printf(), getch(), strlen(), strcmp(),
strcat(), sqrt(), pow()
are this are library functions.
User Defined Functions
 User defined functions are self-contained blocks of

statements which are written by the user to compute
or perform a task.
 They can be called by the main program repeatedly as

per the requirement.
Uses of functions
 They are very much useful when a block of statements

has to be written/executed again and again.
 They are useful when program size are too large and
complex.
 It works like top-down modular programming
technique to solve a problem.
 They are also used to reduce the difficulties during
debugging a program.
ELEMENTS OF USER-DEFINED
FUNCTION
 In order to make use of user-defined functions, we

need to establish three elements that are related to
functions.
 Function declaration
 Function Call
 Function definition
Function declaration
Syntax:
function_type function_name(arguments list);

Ex.
int add(int , int);
Function call
The program that calls the function is referred to as the
calling program or calling functions
Syntax:
function_name(actual parameters);
Ex.
add(a,b);
Function definition
The function definition is an
independent program module
that is specially written or
implement the requirements of
the function.
main()
{
function1();
….
function2();
}
function1()
{
…
}
function2()
{
…
function1();
}
Types of functions
1) Function with no arguments & no return value.

Function with arguments & no return value.
3) Function with arguments & return one value.
4) Function with no arguments & return one value.
5) Function return multiple values.
2)
Function with no arguments & no
return value.
void series( );
main( )
{
series( ); /* function called */
getch( );
}
Void series( )
{
int x , n , i , s=0;
printf(“Enter the value x & n”);
Scanf(“%d%d”, &x ,&n);
For(i=1; i<=n; i++)
s=s+pow(x,i);
Printf(“Sum of series is %d”,s);
}
Function with arguments & no
return value
void series(int , int);
main( )
{
int x , n;
printf(“”Enter the value of x & n);
scanf(“%d%d”,&x&n);
series(x,n); /* function call with actual
arguments */
getch();
}
void series(int x , int n)
{
int i , s=0;
for(i=1;i<=n;i++);
s=s+pow(x,i);
printf(“Sum of series is %d”,s);
}
Functions with arguments & return
one value
int series(int , int);
main( )
{
int x , n , r;
printf(“Enter x & n”);
Scanf(“%d%d”,&x&n);
r=series(x,n);
printf(“Sum of series is %d”,r);
getch( );
}
int series(int x , int n)
{
int i , s=0;
for(i=1;i<=n;i++)
s=s+pow(x,i);
return(s);
}
Function with no argument & no
return value
int series( );
main( )
{
int r;
r=series( );
printf(“Sum of series %d”,r);
getch( );
}
int series( )
{
int x , n , i , s=0;
printf(“Enter x & n”);
scanf(“%d%d”,&x,&n);
for(i=1;i<=n;i++)
s=s+pow(x,i);
return(s);
}
Function return multiple values
int check( );
main( )
{
int r;
r=check( );
if(r==1)
pintf(“Even number”);
else
printf(“Odd number”);
getch( );
}
int check( )
{
int n;
printf(“Enter a number”);
scanf(“%d”,&n);
if(n%2==0);
return(1);
else
return(0);
}
Thank you

Contenu connexe

Tendances (20)

Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
C functions
C functionsC functions
C functions
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Pointers
PointersPointers
Pointers
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Function in c
Function in cFunction in c
Function in c
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Inline function
Inline functionInline function
Inline function
 

Similaire à User defined functions in C (20)

Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Functions
FunctionsFunctions
Functions
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Function
FunctionFunction
Function
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
C functions list
C functions listC functions list
C functions list
 
c.p function
c.p functionc.p function
c.p function
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions
Functions Functions
Functions
 
Basic information of function in cpu
Basic information of function in cpuBasic information of function in cpu
Basic information of function in cpu
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Function
FunctionFunction
Function
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
Functions in c
Functions in cFunctions in c
Functions in c
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 
Unit 8
Unit 8Unit 8
Unit 8
 
Function in C
Function in CFunction in C
Function in C
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptx
 

Plus de Harendra Singh

Plus de Harendra Singh (6)

Cyber crime
Cyber crimeCyber crime
Cyber crime
 
Google glass
Google glassGoogle glass
Google glass
 
Chromebook
ChromebookChromebook
Chromebook
 
Hacking
Hacking Hacking
Hacking
 
Computer viruses
Computer virusesComputer viruses
Computer viruses
 
E-learning vs Classroom learning
E-learning vs Classroom learningE-learning vs Classroom learning
E-learning vs Classroom learning
 

Dernier

Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updateadam112203
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsDianaGray10
 
Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...DianaGray10
 
Where developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingWhere developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingFrancesco Corti
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptxHansamali Gamage
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud DataEric D. Schabell
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNeo4j
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfInfopole1
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and businessFrancesco Corti
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applicationsnooralam814309
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0DanBrown980551
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3DianaGray10
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxNeo4j
 
AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024Brian Pichman
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInThousandEyes
 
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTSIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTxtailishbaloch
 
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechWebinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechProduct School
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdfThe Good Food Institute
 

Dernier (20)

Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 update
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projects
 
Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...Explore the UiPath Community and ways you can benefit on your journey to auto...
Explore the UiPath Community and ways you can benefit on your journey to auto...
 
Where developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is goingWhere developers are challenged, what developers want and where DevEx is going
Where developers are challenged, what developers want and where DevEx is going
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4j
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdf
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and business
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applications
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
 
AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024AI Workshops at Computers In Libraries 2024
AI Workshops at Computers In Libraries 2024
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
 
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTSIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
 
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechWebinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf
 
SheDev 2024
SheDev 2024SheDev 2024
SheDev 2024
 

User defined functions in C

  • 2. Definition  A set of statements working together with common goal is known as function.  Also known as subprograms which are used to compute a value or perform a specific task.  They can’t run independently and are always called by the main() program or by some other function.
  • 3. Categories of functions Library functions User-Defined functions
  • 4. Library functions These are also known as Pre defined functions. Ex. scanf(), printf(), getch(), strlen(), strcmp(), strcat(), sqrt(), pow() are this are library functions.
  • 5. User Defined Functions  User defined functions are self-contained blocks of statements which are written by the user to compute or perform a task.  They can be called by the main program repeatedly as per the requirement.
  • 6. Uses of functions  They are very much useful when a block of statements has to be written/executed again and again.  They are useful when program size are too large and complex.  It works like top-down modular programming technique to solve a problem.  They are also used to reduce the difficulties during debugging a program.
  • 7. ELEMENTS OF USER-DEFINED FUNCTION  In order to make use of user-defined functions, we need to establish three elements that are related to functions.  Function declaration  Function Call  Function definition
  • 9. Function call The program that calls the function is referred to as the calling program or calling functions Syntax: function_name(actual parameters); Ex. add(a,b);
  • 10. Function definition The function definition is an independent program module that is specially written or implement the requirements of the function.
  • 12. Types of functions 1) Function with no arguments & no return value. Function with arguments & no return value. 3) Function with arguments & return one value. 4) Function with no arguments & return one value. 5) Function return multiple values. 2)
  • 13. Function with no arguments & no return value. void series( ); main( ) { series( ); /* function called */ getch( ); }
  • 14. Void series( ) { int x , n , i , s=0; printf(“Enter the value x & n”); Scanf(“%d%d”, &x ,&n); For(i=1; i<=n; i++) s=s+pow(x,i); Printf(“Sum of series is %d”,s); }
  • 15. Function with arguments & no return value void series(int , int); main( ) { int x , n; printf(“”Enter the value of x & n); scanf(“%d%d”,&x&n); series(x,n); /* function call with actual arguments */ getch(); }
  • 16. void series(int x , int n) { int i , s=0; for(i=1;i<=n;i++); s=s+pow(x,i); printf(“Sum of series is %d”,s); }
  • 17. Functions with arguments & return one value int series(int , int); main( ) { int x , n , r; printf(“Enter x & n”); Scanf(“%d%d”,&x&n); r=series(x,n); printf(“Sum of series is %d”,r); getch( ); }
  • 18. int series(int x , int n) { int i , s=0; for(i=1;i<=n;i++) s=s+pow(x,i); return(s); }
  • 19. Function with no argument & no return value int series( ); main( ) { int r; r=series( ); printf(“Sum of series %d”,r); getch( ); }
  • 20. int series( ) { int x , n , i , s=0; printf(“Enter x & n”); scanf(“%d%d”,&x,&n); for(i=1;i<=n;i++) s=s+pow(x,i); return(s); }
  • 21. Function return multiple values int check( ); main( ) { int r; r=check( ); if(r==1) pintf(“Even number”); else printf(“Odd number”); getch( ); }
  • 22. int check( ) { int n; printf(“Enter a number”); scanf(“%d”,&n); if(n%2==0); return(1); else return(0); }