SlideShare a Scribd company logo
1 of 6
Download to read offline
You will be implementing the following functions. You may modify the main to test the
functions, but this programwill work as a starting point.
//********** Function Prototypes ******************
//function isPrime
//input parameter - positive integer greater than 1
//returns true if the number is prime, otherwise false
//
bool isPrime (int number);
//function findPrimes
//input parameter - positive integer
//Uses the isPrime method to print a list of prime numbers between 1 and n.
void findPrimes (int n);
//function findFibo
//input parameter - positive integer
//returns the nth fibonacci number where
//Fib(0) -> 0
//Fib(1) -> 1
//Fib(N) -> Fib(N-2) + Fib(N-1)
//Note: You must use a loop in your solution. Also, if passed a 0, return 0.
int findFibo (int n);
//function findFactors
//input parameter - positive integer
//prints the prime factors of the given number to standard output (cout)
//example output: 52=2*2*13 (or 52=1*2*2*13) or 13=prime
//Hint: You will need nested loops for your solution.
void findFactors (int number);
Solution
#include
#include
using namespace std;
//********** Function Prototypes ******************
//function isPrime
//input parameter - positive integer greater than 1
//returns true if the number is prime, otherwise false
//
bool isPrime (int number);
//function findPrimes
//input parameter - positive integer
//Uses the isPrime method to print a list of prime numbers between 1 and n.
void findPrimes (int n);
//function findFibo
//input parameter - positive integer
//returns the nth fibonacci number where
//Fib(0) -> 0
//Fib(1) -> 1
//Fib(N) -> Fib(N-2) + Fib(N-1)
//Note: You must use a loop in your solution. Also, if passed a 0, return 0.
int findFibo (int n);
//function findFactors
//input parameter - positive integer
//prints the prime factors of the given number to standard output (cout)
//example output: 52=2*2*13 (or 52=1*2*2*13) or 13=prime
//Hint: You will need nested loops for your solution.
void findFactors (int number);
//****************** MAIN *****************************
int main ()
{
int testNum;
//test for the isPrime function
cout << "Enter a test number - ";
cin >> testNum;
cout << endl;
if (isPrime(testNum))
cout << testNum << " is prime." << endl;
else
cout << testNum << " is not prime." << endl;
//test for how many primes
cout << "Enter n to print the prime numbers between 1 and n: ";
cin >> testNum;
cout << endl;
findPrimes(testNum);
cout << endl;
//test for Fibonacci number finder
cout << "Which Fibonacci number? ";
cin >> testNum;
cout << endl;
cout << "The " << testNum << " Fibonacci number is : " << findFibo(testNum) << endl;
cout << endl;
//test for prime factors
cout << "Factor what number: ";
cin >> testNum;
cout << endl;
findFactors(testNum);
return 0;
}
//function isPrime
//input parameter - positive integer greater than 1
//returns true if the number is prime, otherwise false
//
bool isPrime (int number)
{
int c, f = 0;
if(number > 1)
{
for(c = 2; c < number; c++)
{
if(number %c == 0)
{
f = 1;
break;
}
}
if(f == 0)
return true;
else
return false;
}
else
{
cout<<" Error: Number must be positive integer greater than 1 ";
}
}
//function findPrimes
//input parameter - positive integer
//Uses the isPrime method to print a list of prime numbers between 1 and n.
void findPrimes (int n)
{
int c;
if(n > 1)
{
for(c = 2; c < n; c++)
{
if(isPrime(c))
cout<<" Prime: "< 0
//Fib(1) -> 1
//Fib(N) -> Fib(N-2) + Fib(N-1)
//Note: You must use a loop in your solution. Also, if passed a 0, return 0.
int findFibo (int n)
{
int t1 = 0, t2 = 1, t3, co = 2;
if(n < 0)
{
cout<<" Error: Number must be positive integer ";
}
else if(n == 0)
{
return 0;
}
else
{
for(; co <= n; co++)
{
t3 = t1 + t2;
t1 = t2;
t2 = t3;
}
return t3;
}
}
//function findFactors
//input parameter - positive integer
//prints the prime factors of the given number to standard output (cout)
//example output: 52=2*2*13 (or 52=1*2*2*13) or 13=prime
//Hint: You will need nested loops for your solution.
void findFactors (int number)
{
int c, d;
if(number < 1)
{
cout<<" Error: Number must be positive integer greater than 1";
}
else
{
for(c = 2; c < number; c++)
{
if(number % c == 0)
{
if(isPrime(c))
cout<

More Related Content

Similar to You will be implementing the following functions. You may modify the.pdf

Fraction.h #include iostream #ifndef FRACTION #define FR.pdf
Fraction.h #include iostream #ifndef FRACTION #define FR.pdfFraction.h #include iostream #ifndef FRACTION #define FR.pdf
Fraction.h #include iostream #ifndef FRACTION #define FR.pdf
ravikapoorindia
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
jyothimuppasani1
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdf
newfaransportsfitnes
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
ezonesolutions
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
Dushmanta Nath
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
CtOlaf
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
josies1
 
C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 

Similar to You will be implementing the following functions. You may modify the.pdf (20)

Fraction.h #include iostream #ifndef FRACTION #define FR.pdf
Fraction.h #include iostream #ifndef FRACTION #define FR.pdfFraction.h #include iostream #ifndef FRACTION #define FR.pdf
Fraction.h #include iostream #ifndef FRACTION #define FR.pdf
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
 
functions
functionsfunctions
functions
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdf
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
 
ICP - Lecture 5
ICP - Lecture 5ICP - Lecture 5
ICP - Lecture 5
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
C important questions
C important questionsC important questions
C important questions
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
03-fortran.ppt
03-fortran.ppt03-fortran.ppt
03-fortran.ppt
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
C++ Function
C++ FunctionC++ Function
C++ Function
 

More from malavshah9013

Fill in parameters Public New Hash table (int initial Capacity, floa.pdf
Fill in parameters Public New Hash table (int initial Capacity, floa.pdfFill in parameters Public New Hash table (int initial Capacity, floa.pdf
Fill in parameters Public New Hash table (int initial Capacity, floa.pdf
malavshah9013
 
For Phantom Limb Syndrome, please describe the symptoms and the part .pdf
For Phantom Limb Syndrome, please describe the symptoms and the part .pdfFor Phantom Limb Syndrome, please describe the symptoms and the part .pdf
For Phantom Limb Syndrome, please describe the symptoms and the part .pdf
malavshah9013
 
Electron transport powers the first steps of photosynthesis. The fo.pdf
Electron transport powers the first steps of photosynthesis. The fo.pdfElectron transport powers the first steps of photosynthesis. The fo.pdf
Electron transport powers the first steps of photosynthesis. The fo.pdf
malavshah9013
 
Describe 5 key traits the lung cancer cells within the primary tumor.pdf
Describe 5 key traits the lung cancer cells within the primary tumor.pdfDescribe 5 key traits the lung cancer cells within the primary tumor.pdf
Describe 5 key traits the lung cancer cells within the primary tumor.pdf
malavshah9013
 
English Composition II - mutiple questions on researchQuestion 1 o.pdf
English Composition II - mutiple questions on researchQuestion 1 o.pdfEnglish Composition II - mutiple questions on researchQuestion 1 o.pdf
English Composition II - mutiple questions on researchQuestion 1 o.pdf
malavshah9013
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdf
malavshah9013
 
Wolves were hunted and poisoned to extinction in Sweden and Norway b.pdf
Wolves were hunted and poisoned to extinction in Sweden and Norway b.pdfWolves were hunted and poisoned to extinction in Sweden and Norway b.pdf
Wolves were hunted and poisoned to extinction in Sweden and Norway b.pdf
malavshah9013
 
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdfDeclaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
malavshah9013
 
Which of the following concepts is exemplified by the story of Parus .pdf
Which of the following concepts is exemplified by the story of Parus .pdfWhich of the following concepts is exemplified by the story of Parus .pdf
Which of the following concepts is exemplified by the story of Parus .pdf
malavshah9013
 

More from malavshah9013 (20)

gen diffuses Oxygen enters a from the blood to red blood cell. the bo.pdf
gen diffuses Oxygen enters a from the blood to red blood cell. the bo.pdfgen diffuses Oxygen enters a from the blood to red blood cell. the bo.pdf
gen diffuses Oxygen enters a from the blood to red blood cell. the bo.pdf
 
Fill in parameters Public New Hash table (int initial Capacity, floa.pdf
Fill in parameters Public New Hash table (int initial Capacity, floa.pdfFill in parameters Public New Hash table (int initial Capacity, floa.pdf
Fill in parameters Public New Hash table (int initial Capacity, floa.pdf
 
For Phantom Limb Syndrome, please describe the symptoms and the part .pdf
For Phantom Limb Syndrome, please describe the symptoms and the part .pdfFor Phantom Limb Syndrome, please describe the symptoms and the part .pdf
For Phantom Limb Syndrome, please describe the symptoms and the part .pdf
 
Explain why the organisms that were studied by Sergei Winogradsky co.pdf
Explain why the organisms that were studied by Sergei Winogradsky co.pdfExplain why the organisms that were studied by Sergei Winogradsky co.pdf
Explain why the organisms that were studied by Sergei Winogradsky co.pdf
 
Electron transport powers the first steps of photosynthesis. The fo.pdf
Electron transport powers the first steps of photosynthesis. The fo.pdfElectron transport powers the first steps of photosynthesis. The fo.pdf
Electron transport powers the first steps of photosynthesis. The fo.pdf
 
Describe 5 key traits the lung cancer cells within the primary tumor.pdf
Describe 5 key traits the lung cancer cells within the primary tumor.pdfDescribe 5 key traits the lung cancer cells within the primary tumor.pdf
Describe 5 key traits the lung cancer cells within the primary tumor.pdf
 
Complete the ANOVA tableSourceDFSSMSBetween Groups35.pdf
Complete the ANOVA tableSourceDFSSMSBetween Groups35.pdfComplete the ANOVA tableSourceDFSSMSBetween Groups35.pdf
Complete the ANOVA tableSourceDFSSMSBetween Groups35.pdf
 
English Composition II - mutiple questions on researchQuestion 1 o.pdf
English Composition II - mutiple questions on researchQuestion 1 o.pdfEnglish Composition II - mutiple questions on researchQuestion 1 o.pdf
English Composition II - mutiple questions on researchQuestion 1 o.pdf
 
Customers arrive at a bank tellers booth at a rate of 2 per minute.pdf
Customers arrive at a bank tellers booth at a rate of 2 per minute.pdfCustomers arrive at a bank tellers booth at a rate of 2 per minute.pdf
Customers arrive at a bank tellers booth at a rate of 2 per minute.pdf
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdf
 
Wolves were hunted and poisoned to extinction in Sweden and Norway b.pdf
Wolves were hunted and poisoned to extinction in Sweden and Norway b.pdfWolves were hunted and poisoned to extinction in Sweden and Norway b.pdf
Wolves were hunted and poisoned to extinction in Sweden and Norway b.pdf
 
Describe the differences between OpenPGP, PGP and GPG.Solution.pdf
Describe the differences between OpenPGP, PGP and GPG.Solution.pdfDescribe the differences between OpenPGP, PGP and GPG.Solution.pdf
Describe the differences between OpenPGP, PGP and GPG.Solution.pdf
 
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdfDeclaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
Declaring a PointerTo define a pointer, use an asterisk, (), in t.pdf
 
Who identified three key economic “advantages” that firms should hav.pdf
Who identified three key economic “advantages” that firms should hav.pdfWho identified three key economic “advantages” that firms should hav.pdf
Who identified three key economic “advantages” that firms should hav.pdf
 
Which of these is the largesta. The surface zoneb. The mixed la.pdf
Which of these is the largesta. The surface zoneb. The mixed la.pdfWhich of these is the largesta. The surface zoneb. The mixed la.pdf
Which of these is the largesta. The surface zoneb. The mixed la.pdf
 
Which of the following concepts is exemplified by the story of Parus .pdf
Which of the following concepts is exemplified by the story of Parus .pdfWhich of the following concepts is exemplified by the story of Parus .pdf
Which of the following concepts is exemplified by the story of Parus .pdf
 
When Elvis swims with the current, he swims 18km in 2 hours. Against.pdf
When Elvis swims with the current, he swims 18km in 2 hours. Against.pdfWhen Elvis swims with the current, he swims 18km in 2 hours. Against.pdf
When Elvis swims with the current, he swims 18km in 2 hours. Against.pdf
 
What tarsal is lateral to the medial cuneiform What tarsal is .pdf
What tarsal is lateral to the medial cuneiform What tarsal is .pdfWhat tarsal is lateral to the medial cuneiform What tarsal is .pdf
What tarsal is lateral to the medial cuneiform What tarsal is .pdf
 
What is the definition of memory access timeA. The difference bet.pdf
What is the definition of memory access timeA. The difference bet.pdfWhat is the definition of memory access timeA. The difference bet.pdf
What is the definition of memory access timeA. The difference bet.pdf
 
What are the main challenges to be dealt within a distributed operat.pdf
What are the main challenges to be dealt within a distributed operat.pdfWhat are the main challenges to be dealt within a distributed operat.pdf
What are the main challenges to be dealt within a distributed operat.pdf
 

Recently uploaded

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
QucHHunhnh
 
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
PECB
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
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
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

You will be implementing the following functions. You may modify the.pdf

  • 1. You will be implementing the following functions. You may modify the main to test the functions, but this programwill work as a starting point. //********** Function Prototypes ****************** //function isPrime //input parameter - positive integer greater than 1 //returns true if the number is prime, otherwise false // bool isPrime (int number); //function findPrimes //input parameter - positive integer //Uses the isPrime method to print a list of prime numbers between 1 and n. void findPrimes (int n); //function findFibo //input parameter - positive integer //returns the nth fibonacci number where //Fib(0) -> 0 //Fib(1) -> 1 //Fib(N) -> Fib(N-2) + Fib(N-1) //Note: You must use a loop in your solution. Also, if passed a 0, return 0. int findFibo (int n); //function findFactors //input parameter - positive integer //prints the prime factors of the given number to standard output (cout) //example output: 52=2*2*13 (or 52=1*2*2*13) or 13=prime //Hint: You will need nested loops for your solution. void findFactors (int number); Solution
  • 2. #include #include using namespace std; //********** Function Prototypes ****************** //function isPrime //input parameter - positive integer greater than 1 //returns true if the number is prime, otherwise false // bool isPrime (int number); //function findPrimes //input parameter - positive integer //Uses the isPrime method to print a list of prime numbers between 1 and n. void findPrimes (int n); //function findFibo //input parameter - positive integer //returns the nth fibonacci number where //Fib(0) -> 0 //Fib(1) -> 1 //Fib(N) -> Fib(N-2) + Fib(N-1) //Note: You must use a loop in your solution. Also, if passed a 0, return 0. int findFibo (int n); //function findFactors //input parameter - positive integer //prints the prime factors of the given number to standard output (cout) //example output: 52=2*2*13 (or 52=1*2*2*13) or 13=prime //Hint: You will need nested loops for your solution. void findFactors (int number); //****************** MAIN ***************************** int main () { int testNum; //test for the isPrime function cout << "Enter a test number - ";
  • 3. cin >> testNum; cout << endl; if (isPrime(testNum)) cout << testNum << " is prime." << endl; else cout << testNum << " is not prime." << endl; //test for how many primes cout << "Enter n to print the prime numbers between 1 and n: "; cin >> testNum; cout << endl; findPrimes(testNum); cout << endl; //test for Fibonacci number finder cout << "Which Fibonacci number? "; cin >> testNum; cout << endl; cout << "The " << testNum << " Fibonacci number is : " << findFibo(testNum) << endl; cout << endl; //test for prime factors cout << "Factor what number: "; cin >> testNum; cout << endl; findFactors(testNum); return 0; } //function isPrime //input parameter - positive integer greater than 1 //returns true if the number is prime, otherwise false // bool isPrime (int number) { int c, f = 0; if(number > 1) { for(c = 2; c < number; c++) {
  • 4. if(number %c == 0) { f = 1; break; } } if(f == 0) return true; else return false; } else { cout<<" Error: Number must be positive integer greater than 1 "; } } //function findPrimes //input parameter - positive integer //Uses the isPrime method to print a list of prime numbers between 1 and n. void findPrimes (int n) { int c; if(n > 1) { for(c = 2; c < n; c++) { if(isPrime(c)) cout<<" Prime: "< 0 //Fib(1) -> 1 //Fib(N) -> Fib(N-2) + Fib(N-1) //Note: You must use a loop in your solution. Also, if passed a 0, return 0. int findFibo (int n) { int t1 = 0, t2 = 1, t3, co = 2; if(n < 0)
  • 5. { cout<<" Error: Number must be positive integer "; } else if(n == 0) { return 0; } else { for(; co <= n; co++) { t3 = t1 + t2; t1 = t2; t2 = t3; } return t3; } } //function findFactors //input parameter - positive integer //prints the prime factors of the given number to standard output (cout) //example output: 52=2*2*13 (or 52=1*2*2*13) or 13=prime //Hint: You will need nested loops for your solution. void findFactors (int number) { int c, d; if(number < 1) { cout<<" Error: Number must be positive integer greater than 1"; } else { for(c = 2; c < number; c++) { if(number % c == 0)