SlideShare a Scribd company logo
1 of 23
Download to read offline
Week 5
Practice
Function
return-value-type function-name(parameter-list) {
statement
return return-value;
}
Function - Sum
a+b
b
a
• Function name is sum
• a and b are integer
Function - Sum
a+b
b
a
Parameter
Function - Sum
a+b
b
a
Return value
Function - Sum
int sum(int a, int b) {
return a+b;
}
a+b
b
a
Function - Sum
#include <stdio.h>
int sum(int a, int b);
int main() {
printf(“%d”, sum(2, 3));
return 0;
}
int sum(int a, int b) {
return a+b;
}
Function - Sum
#include <stdio.h>
int sum(int a, int b);
int main() {
printf(“%d”, sum(2, 3));
return 0;
}
int sum(int a, int b) {
return a+b;
}
Function - Sum
#include <stdio.h>
int sum(int a, int b);
int main() {
printf(“%d”, sum(2, 3));
return 0;
}
int sum(int a, int b) {
return a+b;
}
Function – 4 Sum
a+b+c+d
c
b a
d
Function – 4 Sum
a+b+c+d
c+d
a+b
d
c
b
a
Function – 4 Sum
#include <stdio.h>
int sum(int a, int b);
int main() {
printf(“%d”, sum(sum(1, 2), sum(3, 4));
return 0;
}
int sum(int a, int b) {
return a+b;
}
Math Library Functions
undefined reference to '<FUNC>'
collect2: ld returned 1 exit status
Open ‘Build Configuration’
menu
undefined reference to '<FUNC>'
collect2: ld returned 1 exit status
Append –lm and apply
Practice 1
𝑁 = 𝑛 + 𝛼
𝑛 𝑖𝑠 𝑖𝑛𝑡𝑒𝑔𝑒𝑟, 0 ≤ 𝛼 < 1
Input
Real number 𝑁 (𝑡𝑤𝑜 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠)
Output
𝑁 = 𝑛 + 𝛼 (𝑁, 𝛼 𝑡𝑤𝑜 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠)
*DO NOT UES if
Ex) Ex)
5.43 0
5.43=5+0.43 0.00=0+0.00
Practice 2
𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0
Input
Real number 𝑎, 𝑏, 𝑐 (𝑎 ≠ 0, 𝑏2
− 4𝑎𝑐 > 0)
Output
Find the value of 𝑥 (𝑡𝑤𝑜 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠)
Ex) Ex)
1 5 3 4.8 15.9 3.2
-0.70 -4.30 -0.22 -3.10
Practice 3
a mod b = 𝑟0
b mod 𝑟0 = 𝑟1
𝑟0 mod 𝑟1 = 𝑟2
…
𝑟𝑛−1 mod 𝑟𝑛 = 0
𝑟𝑛 is the greatest common divisor (gcd) of a and b
For example,
1071 mod 462 = 147
462 mod 147 = 21
147 mod 21 = 0
21 is the greatest common divisor (gcd) of 1071 and 462
Practice 3
Input
Natural number a, b
Output
GCD of a and b
*Create functions: gcd
Ex) Ex) Ex)
1071 462 30 8 24 56
21 2 8
Homework - Continued fractions
𝑚
𝑛
= 𝑎0 +
1
𝑎1 +
1
𝑎2 +
1
⋱ +
1
𝑎 𝑛
For example,
12
5
= 2 +
2
5
= 2 +
1
5
2
= 2 +
1
2 +
1
2
Homework - Continued fractions
1071
462
= 2 +
1
3 +
1
7
3
4
= 0 +
1
1 +
1
3
43
23
= 1 +
1
1 +
1
6 +
1
1 +
1
2
Homework - Continued fractions
Input
Natural number m, n
Output
𝑎0, 𝑎1, 𝑎2, ⋯ , 𝑎 𝑛
Ex) Ex) Ex)
1071 462 1234 2345 3 4
2 3 7 0 1 1 9 30 1 3 0 1 3

More Related Content

What's hot

Regex, Python & Twitter
Regex, Python & TwitterRegex, Python & Twitter
Regex, Python & TwitterStelian Firez
 
Alg 2 : multiply ing & factoring
Alg 2 : multiply ing & factoringAlg 2 : multiply ing & factoring
Alg 2 : multiply ing & factoringpaksukur
 
Translating Linear Functions "I AM" Answer Key!
Translating Linear Functions "I AM" Answer Key!Translating Linear Functions "I AM" Answer Key!
Translating Linear Functions "I AM" Answer Key!Deborah_Johnson
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1rohit kumar
 
Array matrix example programs - C language
Array matrix example programs - C languageArray matrix example programs - C language
Array matrix example programs - C languageSk_Group
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++Bharat Kalia
 
Extending built in objects
Extending built in objectsExtending built in objects
Extending built in objectsMuhammad Ahmed
 
敵対的生成ネットワークによる食事画像の変換に関する研究
敵対的生成ネットワークによる食事画像の変換に関する研究敵対的生成ネットワークによる食事画像の変換に関する研究
敵対的生成ネットワークによる食事画像の変換に関する研究Ryosuke Tanno
 
1 borland c++ 5.02 by aramse
1   borland c++ 5.02 by aramse1   borland c++ 5.02 by aramse
1 borland c++ 5.02 by aramseAram SE
 
Write a program to perform translation.
 Write a program to perform translation. Write a program to perform translation.
Write a program to perform translation.Shobhit Saxena
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd StudyChris Ohk
 

What's hot (20)

Regex, Python & Twitter
Regex, Python & TwitterRegex, Python & Twitter
Regex, Python & Twitter
 
Practical no 3
Practical no 3Practical no 3
Practical no 3
 
Alg 2 : multiply ing & factoring
Alg 2 : multiply ing & factoringAlg 2 : multiply ing & factoring
Alg 2 : multiply ing & factoring
 
Translating Linear Functions "I AM" Answer Key!
Translating Linear Functions "I AM" Answer Key!Translating Linear Functions "I AM" Answer Key!
Translating Linear Functions "I AM" Answer Key!
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
 
Array matrix example programs - C language
Array matrix example programs - C languageArray matrix example programs - C language
Array matrix example programs - C language
 
Include
IncludeInclude
Include
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
Extending built in objects
Extending built in objectsExtending built in objects
Extending built in objects
 
敵対的生成ネットワークによる食事画像の変換に関する研究
敵対的生成ネットワークによる食事画像の変換に関する研究敵対的生成ネットワークによる食事画像の変換に関する研究
敵対的生成ネットワークによる食事画像の変換に関する研究
 
1 borland c++ 5.02 by aramse
1   borland c++ 5.02 by aramse1   borland c++ 5.02 by aramse
1 borland c++ 5.02 by aramse
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
Write a program to perform translation.
 Write a program to perform translation. Write a program to perform translation.
Write a program to perform translation.
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Ooprc4 b
Ooprc4 bOoprc4 b
Ooprc4 b
 
C++ examples &revisions
C++ examples &revisionsC++ examples &revisions
C++ examples &revisions
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 

Viewers also liked

Curriculum vitae herzien (2)
Curriculum vitae herzien (2)Curriculum vitae herzien (2)
Curriculum vitae herzien (2)HarryCP60
 
Makalah google drive & kalender
Makalah google drive & kalenderMakalah google drive & kalender
Makalah google drive & kalenderHananda Elf
 
10 Tips for Coin Store Design
10 Tips for Coin Store Design10 Tips for Coin Store Design
10 Tips for Coin Store DesignScientificRevenue
 
Makalah membuat blog dan wordpress
Makalah membuat blog dan wordpressMakalah membuat blog dan wordpress
Makalah membuat blog dan wordpressHananda Elf
 
Causal Inference, Reinforcement Learning, and Continuous Optimization
Causal Inference, Reinforcement Learning, and Continuous OptimizationCausal Inference, Reinforcement Learning, and Continuous Optimization
Causal Inference, Reinforcement Learning, and Continuous OptimizationScientificRevenue
 
Teaching with Academic Social Networks and Self Regulated Learning in University
Teaching with Academic Social Networks and Self Regulated Learning in UniversityTeaching with Academic Social Networks and Self Regulated Learning in University
Teaching with Academic Social Networks and Self Regulated Learning in Universityanagroba
 

Viewers also liked (15)

Blue-Skies-Brochure
Blue-Skies-BrochureBlue-Skies-Brochure
Blue-Skies-Brochure
 
Curriculum vitae herzien (2)
Curriculum vitae herzien (2)Curriculum vitae herzien (2)
Curriculum vitae herzien (2)
 
Week3
Week3Week3
Week3
 
Makalah google drive & kalender
Makalah google drive & kalenderMakalah google drive & kalender
Makalah google drive & kalender
 
Presentation
PresentationPresentation
Presentation
 
Final
FinalFinal
Final
 
DOS AmberAdam
DOS AmberAdamDOS AmberAdam
DOS AmberAdam
 
Scientific Revenue and R
Scientific Revenue and RScientific Revenue and R
Scientific Revenue and R
 
10 Tips for Coin Store Design
10 Tips for Coin Store Design10 Tips for Coin Store Design
10 Tips for Coin Store Design
 
Kano model
Kano modelKano model
Kano model
 
Makalah membuat blog dan wordpress
Makalah membuat blog dan wordpressMakalah membuat blog dan wordpress
Makalah membuat blog dan wordpress
 
The Future of Economics
The Future of EconomicsThe Future of Economics
The Future of Economics
 
Causal Inference, Reinforcement Learning, and Continuous Optimization
Causal Inference, Reinforcement Learning, and Continuous OptimizationCausal Inference, Reinforcement Learning, and Continuous Optimization
Causal Inference, Reinforcement Learning, and Continuous Optimization
 
Teaching with Academic Social Networks and Self Regulated Learning in University
Teaching with Academic Social Networks and Self Regulated Learning in UniversityTeaching with Academic Social Networks and Self Regulated Learning in University
Teaching with Academic Social Networks and Self Regulated Learning in University
 
Cultural awareness training
Cultural awareness trainingCultural awareness training
Cultural awareness training
 

Similar to Week 5

Lab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceLab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceranaibrahim453
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functionsTAlha MAlik
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxssuser3cbb4c
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaPriyanka Rana
 
OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++Allan Sun
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
SPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in CSPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in CMohammad Imam Hossain
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignmentJunaid Ahmed
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Codemotion
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 

Similar to Week 5 (20)

Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 
Session06 functions
Session06 functionsSession06 functions
Session06 functions
 
Lab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practiceLab Manual IV (1).pdf on C++ Programming practice
Lab Manual IV (1).pdf on C++ Programming practice
 
901131 examples
901131 examples901131 examples
901131 examples
 
Vcs9
Vcs9Vcs9
Vcs9
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 
array2d.ppt
array2d.pptarray2d.ppt
array2d.ppt
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 
OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++
 
C++ Programm.pptx
C++ Programm.pptxC++ Programm.pptx
C++ Programm.pptx
 
10.ppt
10.ppt10.ppt
10.ppt
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
SPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in CSPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in C
 
6. function
6. function6. function
6. function
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignment
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 

Recently uploaded

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

Week 5

  • 3. Function - Sum a+b b a • Function name is sum • a and b are integer
  • 6. Function - Sum int sum(int a, int b) { return a+b; } a+b b a
  • 7. Function - Sum #include <stdio.h> int sum(int a, int b); int main() { printf(“%d”, sum(2, 3)); return 0; } int sum(int a, int b) { return a+b; }
  • 8. Function - Sum #include <stdio.h> int sum(int a, int b); int main() { printf(“%d”, sum(2, 3)); return 0; } int sum(int a, int b) { return a+b; }
  • 9. Function - Sum #include <stdio.h> int sum(int a, int b); int main() { printf(“%d”, sum(2, 3)); return 0; } int sum(int a, int b) { return a+b; }
  • 10. Function – 4 Sum a+b+c+d c b a d
  • 11. Function – 4 Sum a+b+c+d c+d a+b d c b a
  • 12. Function – 4 Sum #include <stdio.h> int sum(int a, int b); int main() { printf(“%d”, sum(sum(1, 2), sum(3, 4)); return 0; } int sum(int a, int b) { return a+b; }
  • 14.
  • 15. undefined reference to '<FUNC>' collect2: ld returned 1 exit status Open ‘Build Configuration’ menu
  • 16. undefined reference to '<FUNC>' collect2: ld returned 1 exit status Append –lm and apply
  • 17. Practice 1 𝑁 = 𝑛 + 𝛼 𝑛 𝑖𝑠 𝑖𝑛𝑡𝑒𝑔𝑒𝑟, 0 ≤ 𝛼 < 1 Input Real number 𝑁 (𝑡𝑤𝑜 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠) Output 𝑁 = 𝑛 + 𝛼 (𝑁, 𝛼 𝑡𝑤𝑜 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠) *DO NOT UES if Ex) Ex) 5.43 0 5.43=5+0.43 0.00=0+0.00
  • 18. Practice 2 𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0 Input Real number 𝑎, 𝑏, 𝑐 (𝑎 ≠ 0, 𝑏2 − 4𝑎𝑐 > 0) Output Find the value of 𝑥 (𝑡𝑤𝑜 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠) Ex) Ex) 1 5 3 4.8 15.9 3.2 -0.70 -4.30 -0.22 -3.10
  • 19. Practice 3 a mod b = 𝑟0 b mod 𝑟0 = 𝑟1 𝑟0 mod 𝑟1 = 𝑟2 … 𝑟𝑛−1 mod 𝑟𝑛 = 0 𝑟𝑛 is the greatest common divisor (gcd) of a and b For example, 1071 mod 462 = 147 462 mod 147 = 21 147 mod 21 = 0 21 is the greatest common divisor (gcd) of 1071 and 462
  • 20. Practice 3 Input Natural number a, b Output GCD of a and b *Create functions: gcd Ex) Ex) Ex) 1071 462 30 8 24 56 21 2 8
  • 21. Homework - Continued fractions 𝑚 𝑛 = 𝑎0 + 1 𝑎1 + 1 𝑎2 + 1 ⋱ + 1 𝑎 𝑛 For example, 12 5 = 2 + 2 5 = 2 + 1 5 2 = 2 + 1 2 + 1 2
  • 22. Homework - Continued fractions 1071 462 = 2 + 1 3 + 1 7 3 4 = 0 + 1 1 + 1 3 43 23 = 1 + 1 1 + 1 6 + 1 1 + 1 2
  • 23. Homework - Continued fractions Input Natural number m, n Output 𝑎0, 𝑎1, 𝑎2, ⋯ , 𝑎 𝑛 Ex) Ex) Ex) 1071 462 1234 2345 3 4 2 3 7 0 1 1 9 30 1 3 0 1 3