SlideShare a Scribd company logo
1 of 2
Please use only ONE recursive?thank you?
Please use c language? thank you?
1. (10 minutes) Write a program called fib.c that calculates the nth fibanocci number. The
equation for the Fibonacci numbers is defined as follows: Fib(0)-0 Fib(1)=1 Fib(N)= Fib(N-1)+
Fib(N-2) 2. Name your executable fib.out 3. Your program should accept N as a command line
argument 4. You MUST solve this program RECURSIVELY 5. Unlike the example in class, you
may only have ONE RECURSIVE CALL in your function 1. Hint pointers help make this
possible. 6. Here are the first 100 numbers in the Fibonacci sequence 7. 7. Examples 1../fib.out 0
2../fib.out 1 3../fib.out 10 The 0th fibanocci number is 0. The 1th fibanocci number is 1. The 10th
fibanocci number is 55.
Solution
//All libraries needed for this program. #include #include #include #include //Function
declarations. void fib(int fibNum1, int fibNum2, int count,int num); //This function takes in the
input and recursively calls itself until it hits the //base cases, where it takes in the input and
returns the nth fibonacci number. void fib(int fibNum1, int fibNum2, int count,int num) { //Base
case where it stops when it is either one or 0 and prints out the //result. if (count <= 1) { // Base
case: ran for user specified // number of steps, do nothing. //This is when the user inputs a 1, it
will print out. if(num == 2 && fibNum1 == 0 && count == 0){ printf("The 1th fibanocci
number is 1."); } //This is when the user inputs a 0, it will print out. else if(num == 2 &&
fibNum1 == 0){ printf("The 0th fibanocci number is 0."); } //Else, this is the classic base case,
where the program will print out the //nth Fibonacci number once it is reduced down to 1. else{
printf("The %dth fibanocci number is %d. ",num, fibNum1 + fibNum2); } } else { // Recursive
case: compute next value num++; fib(fibNum2, fibNum1 + fibNum2, count - 1,num); } return; }
//Main function that will run int main(int argc,char**argv) { //Variable declarations. int runFor =
0; runFor = atoi(argv[1]); // User specified number of values computed int num = 2; //Function
call to the function fib. fib(0, 1, runFor-1,num); return 0; }
C Recursive Fibonacci Calculator

More Related Content

Similar to C Recursive Fibonacci Calculator

Exploring Tailrec Through Time Until Kotlin.pptx
Exploring Tailrec Through Time Until Kotlin.pptxExploring Tailrec Through Time Until Kotlin.pptx
Exploring Tailrec Through Time Until Kotlin.pptxJoão Esperancinha
 
I need help coming up with a MIPS program for this.1.3. Overvi.pdf
I need help coming up with a MIPS program for this.1.3. Overvi.pdfI need help coming up with a MIPS program for this.1.3. Overvi.pdf
I need help coming up with a MIPS program for this.1.3. Overvi.pdfpratyushraj61
 
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docxCMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docxclarebernice
 
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili SaghafiEffective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili SaghafiProfessor Lili Saghafi
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxAASTHA76
 
OP 3014 Assignment 02 Please read about the Fibonacci numbers at http:...
OP 3014  Assignment 02  Please read about the Fibonacci numbers at      http:...OP 3014  Assignment 02  Please read about the Fibonacci numbers at      http:...
OP 3014 Assignment 02 Please read about the Fibonacci numbers at http:...hwbloom39
 
Modularization & Catch Statement
Modularization & Catch StatementModularization & Catch Statement
Modularization & Catch Statementsapdocs. info
 
컴퓨터 프로그램의 구조와 해석 1.2
컴퓨터  프로그램의 구조와 해석 1.2컴퓨터  프로그램의 구조와 해석 1.2
컴퓨터 프로그램의 구조와 해석 1.2HyeonSeok Choi
 
Python recursion
Python recursionPython recursion
Python recursionToniyaP1
 
I need help getting my mips program completed this are the full inst.pdf
I need help getting my mips program completed this are the full inst.pdfI need help getting my mips program completed this are the full inst.pdf
I need help getting my mips program completed this are the full inst.pdfallurafashions98
 
01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms NotesAndres Mendez-Vazquez
 
Catastrophic Cancellation
Catastrophic CancellationCatastrophic Cancellation
Catastrophic CancellationC4Media
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
 
Concept_of_NAN_IND_INF_DEN_Using_C++
Concept_of_NAN_IND_INF_DEN_Using_C++Concept_of_NAN_IND_INF_DEN_Using_C++
Concept_of_NAN_IND_INF_DEN_Using_C++Mohammed Nisamudheen
 

Similar to C Recursive Fibonacci Calculator (20)

Exploring Tailrec Through Time Until Kotlin.pptx
Exploring Tailrec Through Time Until Kotlin.pptxExploring Tailrec Through Time Until Kotlin.pptx
Exploring Tailrec Through Time Until Kotlin.pptx
 
Recursion.pdf
Recursion.pdfRecursion.pdf
Recursion.pdf
 
14. Recursion.pdf
14. Recursion.pdf14. Recursion.pdf
14. Recursion.pdf
 
I need help coming up with a MIPS program for this.1.3. Overvi.pdf
I need help coming up with a MIPS program for this.1.3. Overvi.pdfI need help coming up with a MIPS program for this.1.3. Overvi.pdf
I need help coming up with a MIPS program for this.1.3. Overvi.pdf
 
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docxCMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
CMIS 102 Hands-On LabWeek 6OverviewThis hands-on lab .docx
 
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili SaghafiEffective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
 
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docxBottom of FormCreate your own FunctionFunctionsFor eac.docx
Bottom of FormCreate your own FunctionFunctionsFor eac.docx
 
Fibonacci using matlab
Fibonacci using matlabFibonacci using matlab
Fibonacci using matlab
 
OP 3014 Assignment 02 Please read about the Fibonacci numbers at http:...
OP 3014  Assignment 02  Please read about the Fibonacci numbers at      http:...OP 3014  Assignment 02  Please read about the Fibonacci numbers at      http:...
OP 3014 Assignment 02 Please read about the Fibonacci numbers at http:...
 
Modularization & Catch Statement
Modularization & Catch StatementModularization & Catch Statement
Modularization & Catch Statement
 
컴퓨터 프로그램의 구조와 해석 1.2
컴퓨터  프로그램의 구조와 해석 1.2컴퓨터  프로그램의 구조와 해석 1.2
컴퓨터 프로그램의 구조와 해석 1.2
 
Defer, Panic, Recover
Defer, Panic, RecoverDefer, Panic, Recover
Defer, Panic, Recover
 
Python recursion
Python recursionPython recursion
Python recursion
 
I need help getting my mips program completed this are the full inst.pdf
I need help getting my mips program completed this are the full inst.pdfI need help getting my mips program completed this are the full inst.pdf
I need help getting my mips program completed this are the full inst.pdf
 
01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes
 
Catastrophic Cancellation
Catastrophic CancellationCatastrophic Cancellation
Catastrophic Cancellation
 
Demo1 use numpy
Demo1 use numpyDemo1 use numpy
Demo1 use numpy
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 
Python PCEP Loops
Python PCEP LoopsPython PCEP Loops
Python PCEP Loops
 
Concept_of_NAN_IND_INF_DEN_Using_C++
Concept_of_NAN_IND_INF_DEN_Using_C++Concept_of_NAN_IND_INF_DEN_Using_C++
Concept_of_NAN_IND_INF_DEN_Using_C++
 

More from rtodd884

Poly-meta-morphic malware looks different each time it is stored on di.docx
Poly-meta-morphic malware looks different each time it is stored on di.docxPoly-meta-morphic malware looks different each time it is stored on di.docx
Poly-meta-morphic malware looks different each time it is stored on di.docxrtodd884
 
Please write a formal summary of the case before proceeding to answer.docx
Please write a formal summary of the case before proceeding to answer.docxPlease write a formal summary of the case before proceeding to answer.docx
Please write a formal summary of the case before proceeding to answer.docxrtodd884
 
Please respond in detail with an example- Thank you! Financial interme.docx
Please respond in detail with an example- Thank you! Financial interme.docxPlease respond in detail with an example- Thank you! Financial interme.docx
Please respond in detail with an example- Thank you! Financial interme.docxrtodd884
 
Problem 1- Text Editor using files and strings using C++ In this proje.docx
Problem 1- Text Editor using files and strings using C++ In this proje.docxProblem 1- Text Editor using files and strings using C++ In this proje.docx
Problem 1- Text Editor using files and strings using C++ In this proje.docxrtodd884
 
Presented below is the balance sheet of Sargent Corporation for the cu.docx
Presented below is the balance sheet of Sargent Corporation for the cu.docxPresented below is the balance sheet of Sargent Corporation for the cu.docx
Presented below is the balance sheet of Sargent Corporation for the cu.docxrtodd884
 
Presented below is information related to Dino Radja Company- Date End.docx
Presented below is information related to Dino Radja Company- Date End.docxPresented below is information related to Dino Radja Company- Date End.docx
Presented below is information related to Dino Radja Company- Date End.docxrtodd884
 
Prepare the journal entry to record salaries payable for the month of.docx
Prepare the journal entry to record salaries payable for the month of.docxPrepare the journal entry to record salaries payable for the month of.docx
Prepare the journal entry to record salaries payable for the month of.docxrtodd884
 
Prepare a short --talking points-- paper in which you identify and dis.docx
Prepare a short --talking points-- paper in which you identify and dis.docxPrepare a short --talking points-- paper in which you identify and dis.docx
Prepare a short --talking points-- paper in which you identify and dis.docxrtodd884
 

More from rtodd884 (8)

Poly-meta-morphic malware looks different each time it is stored on di.docx
Poly-meta-morphic malware looks different each time it is stored on di.docxPoly-meta-morphic malware looks different each time it is stored on di.docx
Poly-meta-morphic malware looks different each time it is stored on di.docx
 
Please write a formal summary of the case before proceeding to answer.docx
Please write a formal summary of the case before proceeding to answer.docxPlease write a formal summary of the case before proceeding to answer.docx
Please write a formal summary of the case before proceeding to answer.docx
 
Please respond in detail with an example- Thank you! Financial interme.docx
Please respond in detail with an example- Thank you! Financial interme.docxPlease respond in detail with an example- Thank you! Financial interme.docx
Please respond in detail with an example- Thank you! Financial interme.docx
 
Problem 1- Text Editor using files and strings using C++ In this proje.docx
Problem 1- Text Editor using files and strings using C++ In this proje.docxProblem 1- Text Editor using files and strings using C++ In this proje.docx
Problem 1- Text Editor using files and strings using C++ In this proje.docx
 
Presented below is the balance sheet of Sargent Corporation for the cu.docx
Presented below is the balance sheet of Sargent Corporation for the cu.docxPresented below is the balance sheet of Sargent Corporation for the cu.docx
Presented below is the balance sheet of Sargent Corporation for the cu.docx
 
Presented below is information related to Dino Radja Company- Date End.docx
Presented below is information related to Dino Radja Company- Date End.docxPresented below is information related to Dino Radja Company- Date End.docx
Presented below is information related to Dino Radja Company- Date End.docx
 
Prepare the journal entry to record salaries payable for the month of.docx
Prepare the journal entry to record salaries payable for the month of.docxPrepare the journal entry to record salaries payable for the month of.docx
Prepare the journal entry to record salaries payable for the month of.docx
 
Prepare a short --talking points-- paper in which you identify and dis.docx
Prepare a short --talking points-- paper in which you identify and dis.docxPrepare a short --talking points-- paper in which you identify and dis.docx
Prepare a short --talking points-- paper in which you identify and dis.docx
 

Recently uploaded

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

C Recursive Fibonacci Calculator

  • 1. Please use only ONE recursive?thank you? Please use c language? thank you? 1. (10 minutes) Write a program called fib.c that calculates the nth fibanocci number. The equation for the Fibonacci numbers is defined as follows: Fib(0)-0 Fib(1)=1 Fib(N)= Fib(N-1)+ Fib(N-2) 2. Name your executable fib.out 3. Your program should accept N as a command line argument 4. You MUST solve this program RECURSIVELY 5. Unlike the example in class, you may only have ONE RECURSIVE CALL in your function 1. Hint pointers help make this possible. 6. Here are the first 100 numbers in the Fibonacci sequence 7. 7. Examples 1../fib.out 0 2../fib.out 1 3../fib.out 10 The 0th fibanocci number is 0. The 1th fibanocci number is 1. The 10th fibanocci number is 55. Solution //All libraries needed for this program. #include #include #include #include //Function declarations. void fib(int fibNum1, int fibNum2, int count,int num); //This function takes in the input and recursively calls itself until it hits the //base cases, where it takes in the input and returns the nth fibonacci number. void fib(int fibNum1, int fibNum2, int count,int num) { //Base case where it stops when it is either one or 0 and prints out the //result. if (count <= 1) { // Base case: ran for user specified // number of steps, do nothing. //This is when the user inputs a 1, it will print out. if(num == 2 && fibNum1 == 0 && count == 0){ printf("The 1th fibanocci number is 1."); } //This is when the user inputs a 0, it will print out. else if(num == 2 && fibNum1 == 0){ printf("The 0th fibanocci number is 0."); } //Else, this is the classic base case, where the program will print out the //nth Fibonacci number once it is reduced down to 1. else{ printf("The %dth fibanocci number is %d. ",num, fibNum1 + fibNum2); } } else { // Recursive case: compute next value num++; fib(fibNum2, fibNum1 + fibNum2, count - 1,num); } return; } //Main function that will run int main(int argc,char**argv) { //Variable declarations. int runFor = 0; runFor = atoi(argv[1]); // User specified number of values computed int num = 2; //Function call to the function fib. fib(0, 1, runFor-1,num); return 0; }