Please do each and every program for each section. THERE ARE 4 questions for voi
ID: 3675851 • Letter: P
Question
Please do each and every program for each section. THERE ARE 4 questions for void, int, void and bool . Please read the "// comment" for instructions on the PROGRAMS You will be implementing the following functions. You may modify the main to test the functions, but this program will work as a starting point. //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) -o //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)Explanation / Answer
#include<iostream.h>
#include<conio.h>
bool isPrime(int number)
{
int i;
for(i=2;i<number-1;i++)
{
if((number%i)==0)
{
return false;
}
}
if(i==number)
return true;
return true;
}
void findPrimes(int n)
{
int i,j;
for(j=1;j<=n;j++)
{
if(isPrime(j))
cout<<j<<endl;
}
}
int findFibo(int n)
{
int a=0b=1,c;
for(i=1;i<=n;i++)
{
c=a+b;
a=b;
b=c;
}
return c;
}
void main()
{
cout<<"Prime number
"<<isPrime(8);
findPrimes(20);
int c=findFibo(10);
cout<<"Last fibo number is ="<<c;
}