User defined functions in C

H
Harendra SinghResearch Software Developer um Confidential
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
1 von 23

Recomendados

Presentation on Function in C Programming von
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
14.4K views17 Folien
Functions in C von
Functions in CFunctions in C
Functions in CKamal Acharya
25.2K views22 Folien
Structure of a C program von
Structure of a C programStructure of a C program
Structure of a C programDavid Livingston J
22.2K views16 Folien
Function in C program von
Function in C programFunction in C program
Function in C programNurul Zakiah Zamri Tan
70.4K views23 Folien
Functions in C von
Functions in CFunctions in C
Functions in CShobhit Upadhyay
4.1K views14 Folien
Static Data Members and Member Functions von
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
3.8K views9 Folien

Más contenido relacionado

Was ist angesagt?

constants, variables and datatypes in C von
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
14.6K views23 Folien
Operators in C Programming von
Operators in C ProgrammingOperators in C Programming
Operators in C Programmingprogramming9
37.7K views19 Folien
RECURSION IN C von
RECURSION IN C RECURSION IN C
RECURSION IN C v_jk
14K views35 Folien
Strings in C von
Strings in CStrings in C
Strings in CKamal Acharya
24K views22 Folien
C functions von
C functionsC functions
C functionsUniversity of Potsdam
9.9K views32 Folien
Structure in C von
Structure in CStructure in C
Structure in CKamal Acharya
35.3K views50 Folien

Was ist angesagt?(20)

Operators in C Programming von programming9
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
programming937.7K views
RECURSION IN C von v_jk
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk14K views
FUNCTIONS IN c++ PPT von 03062679929
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
0306267992925.3K views
Functions in python von colorsof
Functions in pythonFunctions in python
Functions in python
colorsof1.4K views
data types in C programming von Harshita Yadav
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav15.6K views
Basic structure of c programming von TejaswiB4
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB43.6K views
arrays and pointers von Samiksha Pun
arrays and pointersarrays and pointers
arrays and pointers
Samiksha Pun3.2K views

Similar a User defined functions in C

Lecture 1_Functions in C.pptx von
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
4 views24 Folien
Functions von
FunctionsFunctions
FunctionsLakshmi Sarvani Videla
93 views20 Folien
VIT351 Software Development VI Unit1 von
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
64 views39 Folien
Function von
FunctionFunction
Functionmshoaib15
18 views15 Folien
Functions struct&union von
Functions struct&unionFunctions struct&union
Functions struct&unionUMA PARAMESWARI
115 views33 Folien
C functions list von
C functions listC functions list
C functions listThesis Scientist Private Limited
476 views11 Folien

Similar a User defined functions in C(20)

VIT351 Software Development VI Unit1 von YOGESH SINGH
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH64 views
c.p function von giri5624
c.p functionc.p function
c.p function
giri56241.4K views

Más de Harendra Singh

Cyber crime von
Cyber crimeCyber crime
Cyber crimeHarendra Singh
2K views17 Folien
Google glass von
Google glassGoogle glass
Google glassHarendra Singh
392 views14 Folien
Chromebook von
ChromebookChromebook
ChromebookHarendra Singh
665 views12 Folien
Hacking von
Hacking Hacking
Hacking Harendra Singh
2K views28 Folien
Computer viruses von
Computer virusesComputer viruses
Computer virusesHarendra Singh
1.3K views24 Folien
E-learning vs Classroom learning von
E-learning vs Classroom learningE-learning vs Classroom learning
E-learning vs Classroom learningHarendra Singh
13K views12 Folien

Último

HTTP headers that make your website go faster - devs.gent November 2023 von
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023Thijs Feryn
22 views151 Folien
Evolving the Network Automation Journey from Python to Platforms von
Evolving the Network Automation Journey from Python to PlatformsEvolving the Network Automation Journey from Python to Platforms
Evolving the Network Automation Journey from Python to PlatformsNetwork Automation Forum
13 views21 Folien
Vertical User Stories von
Vertical User StoriesVertical User Stories
Vertical User StoriesMoisés Armani Ramírez
14 views16 Folien
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf von
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdfDr. Jimmy Schwarzkopf
19 views29 Folien
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive von
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
31 views35 Folien
PRODUCT PRESENTATION.pptx von
PRODUCT PRESENTATION.pptxPRODUCT PRESENTATION.pptx
PRODUCT PRESENTATION.pptxangelicacueva6
14 views1 Folie

Último(20)

HTTP headers that make your website go faster - devs.gent November 2023 von Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 views
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf von Dr. Jimmy Schwarzkopf
STKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdfSTKI Israeli Market Study 2023   corrected forecast 2023_24 v3.pdf
STKI Israeli Market Study 2023 corrected forecast 2023_24 v3.pdf
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive von Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Unit 1_Lecture 2_Physical Design of IoT.pdf von StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
Transcript: The Details of Description Techniques tips and tangents on altern... von BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada136 views
STPI OctaNE CoE Brochure.pdf von madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
Serverless computing with Google Cloud (2023-24) von wesley chun
Serverless computing with Google Cloud (2023-24)Serverless computing with Google Cloud (2023-24)
Serverless computing with Google Cloud (2023-24)
wesley chun11 views
Case Study Copenhagen Energy and Business Central.pdf von Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 views
Special_edition_innovator_2023.pdf von WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2217 views
Data Integrity for Banking and Financial Services von Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely21 views
Voice Logger - Telephony Integration Solution at Aegis von Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... von Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors von sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views
Five Things You SHOULD Know About Postman von Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman33 views

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); }