SlideShare une entreprise Scribd logo
1  sur  23
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
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Functions in c
Functions in cFunctions in c
Functions in c
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
File Management in C
File Management in CFile Management in C
File Management in C
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Functions in C
Functions in CFunctions in C
Functions in C
 
File handling in c
File handling in cFile handling in c
File handling in c
 
C functions
C functionsC functions
C functions
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 

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

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Dernier (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

User defined functions in C

  • 1.
  • 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); }