SlideShare une entreprise Scribd logo
1  sur  17
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

Contenu connexe

Tendances (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
 

Similaire à Programming in c function

Similaire à 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
 

Plus de 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).pptxParvez Ahmed
 
Transportation Engineering Sessional Presentation.pptx
Transportation Engineering Sessional Presentation.pptxTransportation Engineering Sessional Presentation.pptx
Transportation Engineering Sessional Presentation.pptxParvez 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.pptxParvez Ahmed
 
Flow through venturimeter
Flow through venturimeterFlow through venturimeter
Flow through venturimeterParvez 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 MachineryParvez Ahmed
 
Road safety in Bangladesh
Road safety in BangladeshRoad safety in Bangladesh
Road safety in BangladeshParvez Ahmed
 

Plus de 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
 

Dernier

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Dernier (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

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