SlideShare a Scribd company logo
COMPUTER
PROGRAMMING
INTRODUCTION TO FUNCTION
CEN 204
2
2
P r e s e n t e d
B y,
C E N 6 8 B 1
G r o u p - 3
• Pranta Biswas
• Md. Saiful Hasan Bhuiyan
• Pallob Sikdar
• Rajib Roy
• Md. Lekhon Miah
• Parvez Ahmed
3
S
F U N C T I O N
Add a Footer 3
A complex problem is often easier to solve by dividing it into
severalsmallerparts,eachofwhichcanbesolvedbyitself.
Thisiscalledstructured programming.
Thesepartsaresometimesmadeintofunctions inC/C++.
main()thenusesthesefunctions tosolvetheoriginalproblem.
4
Add a Footer 4
F U N C T I O N
D E F I N I T I O N
The function definition can be placed anywhere
intheprogramafterthefunction prototypes.
Ifafunctiondefinitionisplacedinfrontofmain(),
there is no need to include its function
prototype.
5
Add a Footer 5
F U N C T I O N
D E F I N I T I O N
A function definition has the following syntax:
<type> <function name>(<parameter list>){
<local declarations>
<sequence of statements>
}
For example: Definition of a function that computes the
absolute value of an integer:
int absolute(int x){
if (x >= 0) return x;
else return -x;
}
6
S
Add a Footer 6
Functions separate the concept (what is done) from the
implementation(howitisdone).
Functionsmakeprogramseasierto understand.
Functions can be called several times in the same program,
allowingthecodetobereused.
A D V A N TA G E O F
F U N C T I O N
7
S
Add a Footer 7
C++ allows the use of both internal (user-defined) and external
functions.
Functionsmakeprogramseasierto understand.
External functions (e.g., abs, ceil, rand, sqrt, etc.)
are usually grouped into specialized libraries (e.g.,
iostream, stdlib, math, etc.)
F U N C T I O N I N C / C + +
8
S
Add a Footer 8
C++programsusually havethefollowing form:
U S E R - D E F I N E D
F U N C T I O N S
// include statements
// function prototypes
// main() function
// function definitions
9
Add a Footer 9
C++programsusuallyhavethefollowing form:
E X T E R N A L F U N C T I O N S
Function Description
acos(x) Inverse cosine of x (in radians)
Asin(x) Inverse sine of x (in radians)
Atan(x) Inverse tangent of x (in radians)
Sin(x) Sine of x (in radians)
Cos(x) Cosine of x (in radians)
Tan(x) Tangent of x (in radians)
*Ceil(x) Ceiling of x (rounds up)
Exp(x) Exponential of x (base e)
Fabs(x) Absolute value of x
*Floor(x) Floor of x (rounds down)
Log(x) Natural logarithm of x (base e)
*Pow(x,p) X to the power p
Sqrt(x) Square root of x
10
10
F U N C T I O N
I N P U T &
O U T P U T
RESULT
PARAMETERS
11
Add a Footer 11
The function prototype declares the input and output
parametersofthefunction.
F U N C T I O N
P R O T O T Y P E
Thefunctionprototype hasthefollowing syntax:
<type> <function name>(<type list>);
Example: A function that returns the absolute value of an
integer is:
int absolute(int);
12
ARGUMENTS/
PARAMETERS
Add a Footer 12
one-to-one correspondence between the arguments
in a function call and the parameters in the function
definition.
int argument1;
double argument2;
// function call (in another function, such as main)
result = thefunctionname(argument1, argument2);
// function definition
int thefunctionname(int parameter1, double parameter2)
{
// Now the function can use the two parameters
// parameter1 = argument 1, parameter2 = argument2
13
Add a Footer 13
Afunctioncallhasthefollowing syntax:
<function name>(<argument list>)
Example: int distance = absolute(-5);
F U N C T I O N C A L L
Theresultofafunctioncallisavalueoftype<type>
14
Add a Footer 14
F U N C T I O N E X A M P L E
15
Add a Footer 15
F U N C T I O N E X A M P L E
16
Add a Footer 16
C O N C L U T I O N
• Our program can determine the Diameter and Cross sectional Area of
aReinforcementBar fromanyBarNumber.
• This program is useful during designing a structure when only a Bar
Numberisgiven.
• Thisprogramisalsocanbeuseinestimatingofreinforcement.
• It is essential for people in the shop and in the field to be able to
identifyataglancethesizesofthebars.
17
Add a Footer 17
F U N C T I O N

More Related Content

What's hot

Function in c
Function in cFunction in c
Function in c
savitamhaske
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
Dr-Dipali Meher
 
Function in c program
Function in c programFunction in c program
Function in c program
CGC Technical campus,Mohali
 
Functions
FunctionsFunctions
Functions
Jesmin Akhter
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
Rupendra Choudhary
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
C# programs
C# programsC# programs
C# programs
Syed Mustafa
 
Functions in c
Functions in cFunctions in c
Functions in c
Innovative
 
Functions in C
Functions in CFunctions in C
Functions in C
Princy Nelson
 
C structure
C structureC structure
C structure
ankush9927
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
MomenMostafa
 
Function in c
Function in cFunction in c
Recursion in c++
Recursion in c++Recursion in c++
Recursion in c++
Abdul Rehman
 
Types of function call
Types of function callTypes of function call
Types of function call
ArijitDhali
 
Assignment12
Assignment12Assignment12
Assignment12
Sunita Milind Dol
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
Dharma Kshetri
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
Dipayan Sarkar
 

What's hot (20)

Function in c
Function in cFunction in c
Function in c
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Functions
FunctionsFunctions
Functions
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
C# programs
C# programsC# programs
C# programs
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions in C
Functions in CFunctions in C
Functions in C
 
C structure
C structureC structure
C structure
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
 
Function in c
Function in cFunction in c
Function in c
 
Recursion in c++
Recursion in c++Recursion in c++
Recursion in c++
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Assignment12
Assignment12Assignment12
Assignment12
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Function in c
Function in cFunction in c
Function in c
 

Similar to Programming in c function

Functions
Functions Functions
Functions
Dr.Subha Krishna
 
C FUNCTIONS
C FUNCTIONSC FUNCTIONS
C FUNCTIONS
TeenaGeorge15
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
Vikash Dhal
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Nikhil Pandit
 
Function in cpu 2
Function in cpu 2Function in cpu 2
Function in cpu 2
Dhaval Jalalpara
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
D-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptxD-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptx
VedantSahane
 
C function presentation
C function presentationC function presentation
C function presentation
Touhidul Shawan
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
KhurramKhan173
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
oggyrao
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
Mehul Desai
 
Presentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakurPresentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakur
Thakurkirtika
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
Sampath Kumar
 
C functions list
C functions listC functions list
eee2-day4-structures engineering college
eee2-day4-structures engineering collegeeee2-day4-structures engineering college
eee2-day4-structures engineering college
2017eee0459
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2

Similar to Programming in c function (20)

Functions
Functions Functions
Functions
 
C FUNCTIONS
C FUNCTIONSC FUNCTIONS
C FUNCTIONS
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
functions
functionsfunctions
functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Function in cpu 2
Function in cpu 2Function in cpu 2
Function in cpu 2
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Function
FunctionFunction
Function
 
Function
FunctionFunction
Function
 
D-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptxD-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptx
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
C function presentation
C function presentationC function presentation
C function presentation
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Presentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakurPresentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakur
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
C functions list
C functions listC functions list
C functions list
 
eee2-day4-structures engineering college
eee2-day4-structures engineering collegeeee2-day4-structures engineering college
eee2-day4-structures engineering college
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 

More from Parvez Ahmed

Flood Analysis of Bangladesh (2001-2005).pptx
Flood Analysis of Bangladesh (2001-2005).pptxFlood Analysis of Bangladesh (2001-2005).pptx
Flood Analysis of Bangladesh (2001-2005).pptx
Parvez Ahmed
 
Transportation Engineering Sessional Presentation.pptx
Transportation Engineering Sessional Presentation.pptxTransportation Engineering Sessional Presentation.pptx
Transportation Engineering Sessional Presentation.pptx
Parvez Ahmed
 
Wastewater Discharge System in Dhaka City.pptx
Wastewater Discharge System in Dhaka City.pptxWastewater Discharge System in Dhaka City.pptx
Wastewater Discharge System in Dhaka City.pptx
Parvez Ahmed
 
Flow through venturimeter
Flow through venturimeterFlow through venturimeter
Flow through venturimeter
Parvez Ahmed
 
A Presentation on Aggregate.
A Presentation on Aggregate.A Presentation on Aggregate.
A Presentation on Aggregate.
Parvez Ahmed
 
A persuasive speech on all universities of bangladesh should not be turned to...
A persuasive speech on all universities of bangladesh should not be turned to...A persuasive speech on all universities of bangladesh should not be turned to...
A persuasive speech on all universities of bangladesh should not be turned to...
Parvez Ahmed
 
Pump and Pumping Machinery
Pump and Pumping MachineryPump and Pumping Machinery
Pump and Pumping Machinery
Parvez Ahmed
 
Road safety in Bangladesh
Road safety in BangladeshRoad safety in Bangladesh
Road safety in Bangladesh
Parvez Ahmed
 

More from Parvez Ahmed (8)

Flood Analysis of Bangladesh (2001-2005).pptx
Flood Analysis of Bangladesh (2001-2005).pptxFlood Analysis of Bangladesh (2001-2005).pptx
Flood Analysis of Bangladesh (2001-2005).pptx
 
Transportation Engineering Sessional Presentation.pptx
Transportation Engineering Sessional Presentation.pptxTransportation Engineering Sessional Presentation.pptx
Transportation Engineering Sessional Presentation.pptx
 
Wastewater Discharge System in Dhaka City.pptx
Wastewater Discharge System in Dhaka City.pptxWastewater Discharge System in Dhaka City.pptx
Wastewater Discharge System in Dhaka City.pptx
 
Flow through venturimeter
Flow through venturimeterFlow through venturimeter
Flow through venturimeter
 
A Presentation on Aggregate.
A Presentation on Aggregate.A Presentation on Aggregate.
A Presentation on Aggregate.
 
A persuasive speech on all universities of bangladesh should not be turned to...
A persuasive speech on all universities of bangladesh should not be turned to...A persuasive speech on all universities of bangladesh should not be turned to...
A persuasive speech on all universities of bangladesh should not be turned to...
 
Pump and Pumping Machinery
Pump and Pumping MachineryPump and Pumping Machinery
Pump and Pumping Machinery
 
Road safety in Bangladesh
Road safety in BangladeshRoad safety in Bangladesh
Road safety in Bangladesh
 

Recently uploaded

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 

Recently uploaded (20)

Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 

Programming in c function

  • 2. 2 2 P r e s e n t e d B y, C E N 6 8 B 1 G r o u p - 3 • Pranta Biswas • Md. Saiful Hasan Bhuiyan • Pallob Sikdar • Rajib Roy • Md. Lekhon Miah • Parvez Ahmed
  • 3. 3 S F U N C T I O N Add a Footer 3 A complex problem is often easier to solve by dividing it into severalsmallerparts,eachofwhichcanbesolvedbyitself. Thisiscalledstructured programming. Thesepartsaresometimesmadeintofunctions inC/C++. main()thenusesthesefunctions tosolvetheoriginalproblem.
  • 4. 4 Add a Footer 4 F U N C T I O N D E F I N I T I O N The function definition can be placed anywhere intheprogramafterthefunction prototypes. Ifafunctiondefinitionisplacedinfrontofmain(), there is no need to include its function prototype.
  • 5. 5 Add a Footer 5 F U N C T I O N D E F I N I T I O N A function definition has the following syntax: <type> <function name>(<parameter list>){ <local declarations> <sequence of statements> } For example: Definition of a function that computes the absolute value of an integer: int absolute(int x){ if (x >= 0) return x; else return -x; }
  • 6. 6 S Add a Footer 6 Functions separate the concept (what is done) from the implementation(howitisdone). Functionsmakeprogramseasierto understand. Functions can be called several times in the same program, allowingthecodetobereused. A D V A N TA G E O F F U N C T I O N
  • 7. 7 S Add a Footer 7 C++ allows the use of both internal (user-defined) and external functions. Functionsmakeprogramseasierto understand. External functions (e.g., abs, ceil, rand, sqrt, etc.) are usually grouped into specialized libraries (e.g., iostream, stdlib, math, etc.) F U N C T I O N I N C / C + +
  • 8. 8 S Add a Footer 8 C++programsusually havethefollowing form: U S E R - D E F I N E D F U N C T I O N S // include statements // function prototypes // main() function // function definitions
  • 9. 9 Add a Footer 9 C++programsusuallyhavethefollowing form: E X T E R N A L F U N C T I O N S Function Description acos(x) Inverse cosine of x (in radians) Asin(x) Inverse sine of x (in radians) Atan(x) Inverse tangent of x (in radians) Sin(x) Sine of x (in radians) Cos(x) Cosine of x (in radians) Tan(x) Tangent of x (in radians) *Ceil(x) Ceiling of x (rounds up) Exp(x) Exponential of x (base e) Fabs(x) Absolute value of x *Floor(x) Floor of x (rounds down) Log(x) Natural logarithm of x (base e) *Pow(x,p) X to the power p Sqrt(x) Square root of x
  • 10. 10 10 F U N C T I O N I N P U T & O U T P U T RESULT PARAMETERS
  • 11. 11 Add a Footer 11 The function prototype declares the input and output parametersofthefunction. F U N C T I O N P R O T O T Y P E Thefunctionprototype hasthefollowing syntax: <type> <function name>(<type list>); Example: A function that returns the absolute value of an integer is: int absolute(int);
  • 12. 12 ARGUMENTS/ PARAMETERS Add a Footer 12 one-to-one correspondence between the arguments in a function call and the parameters in the function definition. int argument1; double argument2; // function call (in another function, such as main) result = thefunctionname(argument1, argument2); // function definition int thefunctionname(int parameter1, double parameter2) { // Now the function can use the two parameters // parameter1 = argument 1, parameter2 = argument2
  • 13. 13 Add a Footer 13 Afunctioncallhasthefollowing syntax: <function name>(<argument list>) Example: int distance = absolute(-5); F U N C T I O N C A L L Theresultofafunctioncallisavalueoftype<type>
  • 14. 14 Add a Footer 14 F U N C T I O N E X A M P L E
  • 15. 15 Add a Footer 15 F U N C T I O N E X A M P L E
  • 16. 16 Add a Footer 16 C O N C L U T I O N • Our program can determine the Diameter and Cross sectional Area of aReinforcementBar fromanyBarNumber. • This program is useful during designing a structure when only a Bar Numberisgiven. • Thisprogramisalsocanbeuseinestimatingofreinforcement. • It is essential for people in the shop and in the field to be able to identifyataglancethesizesofthebars.
  • 17. 17 Add a Footer 17 F U N C T I O N