SlideShare a Scribd company logo
Function

A function is a set of
statements, written in a
particular language that
performs a particular
task ,when ever called.
Types of functions
1.Inbuilt or system defined or Library Functions

2.User defined Functions
Inbuilt functions
These are the functions whose defintions is
already defined and stored in a respective
header files of c library .
Example of this type of functions are
gets(),puts(),clrscr(),getche(),printf(),scanf().
Etc.
User defined functions
 The functions which are created by the user

to, perform the desired task,are called user
defined functions.
User defined functions provide the following
Benefits:1.By using user defined functions,we can divide
a large problem into small independence
modules,each having a defined purpose.the
process is called modulation.
benefits
2.Smaller modules are easy to design and
debug.
3.We can create own user defined functions,in
the way,a function can be created once and
used for many times.i.e sharing of the code.
4Modulation provide greater clarity to the
programs.
Defining a function
Syntax :<return type><name>(parameterlist)>
{
Statement 1;
Statement 2;
----------------Statement n;
Return (expression);
}
Elements of functions
1. Return type :- is datatype of the value ,returned
by the function .void is used when the function
does not return any value,int and float are used
when functions returns integer or floating point
values.
2.Name:-is the name of the function
3.Parameter list:-contain variables carrying
information from the main function.
4 Function call is represented by writing the name
of the function followed by braces and
semicolon;
Example describes a function to calc sum of two
no.
Int sum(int a,int b)
{
// function body
Printf(“the sum of no is being calculated”);
Return(a+b);
}
Void main()
{
Int j=0;
Int k=10;
Int m=12;
J=sum(k,m);
//call to sum function
Printf(“the sum is %d”,j);
}
Return type of the function is “int”.the name of
the function is “sum” .the parameter are” a”
and “b” of integer type.

C allows us to define user defined function in
various ways.we can define the functions in
following ways:
1. Functions with no argument and no return
type.
2. Function with argument and no return type.
3. Functions with argument and with return type
like int ,float.
Functions with no argument
and no return type.
These are the simple function which
do not take any data from calling
functions, in the form of parameters
and do not return anything to calling
functions, after execution.
The example describes the use of func.
with no parameter and no return type

Simple function.
#include<stdio.h>
#include<conio.h>
Void main()
{
void punjab();
//function prototyping
Void delhi();
//function prototyping
Printf(“n I m from main”);
Punjab();
// call to punjab()
Printf(“nt I m back in main”);
Himachal();
Print f(“nt t I m from main again”);
}
Void punjab()
{
Printf(“n I m from punjab”);
}
Void himachal()
{
Print(“n I m from himachal”);
}
output
I m from main
I m from punjab
I m back in main
I m from himchal
I m from main again
The example describes the use of func.
with no parameter and return type

Example to calculate the sum of two numbers
using
#include<stdio.h>
#include<conio.h>
Void main()
{
Int sum();
Int result();
Clrscr();
Printf(“calculate sum of two numbers “);
Getch();
Result=sum();
call to function sum
//result contains the value entered
Printf(“n the result after adding is number
%d”,result);
Getch();
}
Int sum()
body of the function
{
Int a,b;
Printf(“n enter 2 numbers”);
Scanf(“%d%d”,&a,&b);
Return(a+b);
}
Out put
Ready to calculate sum of two numbers-press
any key
Enter 2 number 12
23
The result after adding numbers is 35
Functions with argu and no return type
 To demonstrate the functions with parameter and

no return
#include<stdio.h>
#include<conio.h>
Void main()
{
Void sum(int,int);
Int a,b;
Printf(“enter 2 numbers”);
Scanf(“%d%”,&a,&b);
Sum(a,b);
Getch();
} //end of main
Void sum(int f1,int f2)
{
Int result;
//variable in function
Result=(f1+f2);
Printf(“n the result after addition is%d”,result);
}
Out put
Enter 2 numbers 10 10
The result after addition is 20
Func with argu and return type
#include<stdio.h>
#include<conio.h>
Void main()
{
Int sum(int,int);
Int a,b,ans;
Printf(“enter 2 numbers”);
Sanf(“%d%d”,&a,&b);
Ans=sum(a,b);
Printf(“n the result after addition is %d”,ans);
Getch();
}
Int sum(int f1,int f2);
{
Int result;
Result=f1+f2;
Return(result);
}
output
 Enter 2 numbers 12 12
 The result after addition is 24

More Related Content

PPTX
Recursive Function
PPTX
Functions in c
PPT
user defined function
PPTX
Functions in C
PPTX
Functions in C
PPT
Recursion in c
PPTX
Function & Recursion
PDF
Lecture20 user definedfunctions.ppt
Recursive Function
Functions in c
user defined function
Functions in C
Functions in C
Recursion in c
Function & Recursion
Lecture20 user definedfunctions.ppt

What's hot (20)

PPTX
Dev Concepts: Functional Programming
PPTX
Function in c language(defination and declaration)
PPTX
Functional programming
PPT
Lecture 11 - Functions
PDF
Some basic FP concepts
PPT
Lecture 13 - Storage Classes
PPT
Function overloading(C++)
PPT
Lecture 14 - Scope Rules
PPTX
C function presentation
DOCX
Basic structure of c programming
PPTX
Functions in c language
PDF
Pointers and call by value, reference, address in C
DOC
Storage classess of C progamming
PDF
Function in C
PPT
RECURSION IN C
PPTX
structured programming
PDF
11 2. variable-scope rule,-storage_class
PDF
Functions
PDF
Python functions
PPTX
Amit user defined functions xi (2)
Dev Concepts: Functional Programming
Function in c language(defination and declaration)
Functional programming
Lecture 11 - Functions
Some basic FP concepts
Lecture 13 - Storage Classes
Function overloading(C++)
Lecture 14 - Scope Rules
C function presentation
Basic structure of c programming
Functions in c language
Pointers and call by value, reference, address in C
Storage classess of C progamming
Function in C
RECURSION IN C
structured programming
11 2. variable-scope rule,-storage_class
Functions
Python functions
Amit user defined functions xi (2)
Ad

Viewers also liked (20)

PPTX
5 steps you have to do on social media before launching
PPT
Movie maker
PDF
Famous Accounting Scandals
PPTX
Slot waddin
 
DOCX
Melanie Richard, RHIT 2016
PDF
Resume Nov 2015
PPTX
Planos seriados
PDF
Certificate of Management Consulting
PDF
Thank you letter from Syria tel
PDF
CadeConnerResume
PPT
Induction address to sec 3 2014
PDF
DOCX
Paduan agamanya ila
PDF
Guia rapido gerenciamento de projetos
PDF
120262739 anc-fisiologis
PPTX
Tugas pratikum 1
PDF
DOC
Hubungan antara infertilitas dengan tingkat depresi pada wanita infertilitas ...
PPT
autism wheel power point
5 steps you have to do on social media before launching
Movie maker
Famous Accounting Scandals
Slot waddin
 
Melanie Richard, RHIT 2016
Resume Nov 2015
Planos seriados
Certificate of Management Consulting
Thank you letter from Syria tel
CadeConnerResume
Induction address to sec 3 2014
Paduan agamanya ila
Guia rapido gerenciamento de projetos
120262739 anc-fisiologis
Tugas pratikum 1
Hubungan antara infertilitas dengan tingkat depresi pada wanita infertilitas ...
autism wheel power point
Ad

Similar to Function (20)

PDF
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
PPTX
Lecture 1_Functions in C.pptx
PPTX
C and C++ functions
PDF
Unit 3 (1)
PDF
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
PPTX
User defined functions in C
PPTX
user-defined_functionsin clanguage .pptx
PPTX
Unit-III.pptx
PDF
Functions in c mrs.sowmya jyothi
PDF
VIT351 Software Development VI Unit1
DOCX
Functions assignment
PDF
[ITP - Lecture 12] Functions in C/C++
PPT
c-Functions power point presentation on c functions
PDF
USER DEFINED FUNCTIONS IN C.pdf
PPT
Ch4 functions
PPTX
User Defined Functionscccccccccccccccccccccccccc.pptx
PPTX
PPTX
Lecture_5_-_Functions_in_C_Detailed.pptx
PPTX
function of C.pptx
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
Lecture 1_Functions in C.pptx
C and C++ functions
Unit 3 (1)
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
User defined functions in C
user-defined_functionsin clanguage .pptx
Unit-III.pptx
Functions in c mrs.sowmya jyothi
VIT351 Software Development VI Unit1
Functions assignment
[ITP - Lecture 12] Functions in C/C++
c-Functions power point presentation on c functions
USER DEFINED FUNCTIONS IN C.pdf
Ch4 functions
User Defined Functionscccccccccccccccccccccccccc.pptx
Lecture_5_-_Functions_in_C_Detailed.pptx
function of C.pptx

More from jasscheema (7)

PPT
Pipelinig hazardous
PPT
Btree
PPT
B+tree
PPTX
Multiole acccess
PPTX
Scheduling
PPTX
Mobile number-portability
PPTX
Presentation1
Pipelinig hazardous
Btree
B+tree
Multiole acccess
Scheduling
Mobile number-portability
Presentation1

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Cell Structure & Organelles in detailed.
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Lesson notes of climatology university.
PDF
RMMM.pdf make it easy to upload and study
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Weekly quiz Compilation Jan -July 25.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Cell Structure & Organelles in detailed.
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Complications of Minimal Access Surgery at WLH
VCE English Exam - Section C Student Revision Booklet
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Microbial disease of the cardiovascular and lymphatic systems
Final Presentation General Medicine 03-08-2024.pptx
Final Presentation General Medicine 03-08-2024.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Lesson notes of climatology university.
RMMM.pdf make it easy to upload and study

Function

  • 1. Function A function is a set of statements, written in a particular language that performs a particular task ,when ever called.
  • 2. Types of functions 1.Inbuilt or system defined or Library Functions 2.User defined Functions
  • 3. Inbuilt functions These are the functions whose defintions is already defined and stored in a respective header files of c library . Example of this type of functions are gets(),puts(),clrscr(),getche(),printf(),scanf(). Etc.
  • 4. User defined functions  The functions which are created by the user to, perform the desired task,are called user defined functions. User defined functions provide the following Benefits:1.By using user defined functions,we can divide a large problem into small independence modules,each having a defined purpose.the process is called modulation.
  • 5. benefits 2.Smaller modules are easy to design and debug. 3.We can create own user defined functions,in the way,a function can be created once and used for many times.i.e sharing of the code. 4Modulation provide greater clarity to the programs.
  • 6. Defining a function Syntax :<return type><name>(parameterlist)> { Statement 1; Statement 2; ----------------Statement n; Return (expression); }
  • 7. Elements of functions 1. Return type :- is datatype of the value ,returned by the function .void is used when the function does not return any value,int and float are used when functions returns integer or floating point values. 2.Name:-is the name of the function 3.Parameter list:-contain variables carrying information from the main function. 4 Function call is represented by writing the name of the function followed by braces and semicolon;
  • 8. Example describes a function to calc sum of two no. Int sum(int a,int b) { // function body Printf(“the sum of no is being calculated”); Return(a+b); } Void main() { Int j=0; Int k=10; Int m=12; J=sum(k,m); //call to sum function Printf(“the sum is %d”,j); }
  • 9. Return type of the function is “int”.the name of the function is “sum” .the parameter are” a” and “b” of integer type. C allows us to define user defined function in various ways.we can define the functions in following ways: 1. Functions with no argument and no return type. 2. Function with argument and no return type. 3. Functions with argument and with return type like int ,float.
  • 10. Functions with no argument and no return type. These are the simple function which do not take any data from calling functions, in the form of parameters and do not return anything to calling functions, after execution.
  • 11. The example describes the use of func. with no parameter and no return type Simple function. #include<stdio.h> #include<conio.h> Void main() { void punjab(); //function prototyping Void delhi(); //function prototyping Printf(“n I m from main”); Punjab(); // call to punjab()
  • 12. Printf(“nt I m back in main”); Himachal(); Print f(“nt t I m from main again”); } Void punjab() { Printf(“n I m from punjab”); } Void himachal() { Print(“n I m from himachal”); }
  • 13. output I m from main I m from punjab I m back in main I m from himchal I m from main again
  • 14. The example describes the use of func. with no parameter and return type Example to calculate the sum of two numbers using #include<stdio.h> #include<conio.h> Void main() { Int sum(); Int result();
  • 15. Clrscr(); Printf(“calculate sum of two numbers “); Getch(); Result=sum(); call to function sum //result contains the value entered Printf(“n the result after adding is number %d”,result); Getch(); } Int sum() body of the function {
  • 16. Int a,b; Printf(“n enter 2 numbers”); Scanf(“%d%d”,&a,&b); Return(a+b); }
  • 17. Out put Ready to calculate sum of two numbers-press any key Enter 2 number 12 23 The result after adding numbers is 35
  • 18. Functions with argu and no return type  To demonstrate the functions with parameter and no return #include<stdio.h> #include<conio.h> Void main() { Void sum(int,int); Int a,b; Printf(“enter 2 numbers”); Scanf(“%d%”,&a,&b); Sum(a,b); Getch();
  • 19. } //end of main Void sum(int f1,int f2) { Int result; //variable in function Result=(f1+f2); Printf(“n the result after addition is%d”,result); }
  • 20. Out put Enter 2 numbers 10 10 The result after addition is 20
  • 21. Func with argu and return type #include<stdio.h> #include<conio.h> Void main() { Int sum(int,int); Int a,b,ans; Printf(“enter 2 numbers”); Sanf(“%d%d”,&a,&b); Ans=sum(a,b); Printf(“n the result after addition is %d”,ans);
  • 22. Getch(); } Int sum(int f1,int f2); { Int result; Result=f1+f2; Return(result); }
  • 23. output  Enter 2 numbers 12 12  The result after addition is 24