Question: QUESTION Please use notations (//) to explain what each line in the code below are calling the program to execute. Part 1: int checkarray(int arr[],int

QUESTION

Please use notations (//) to explain what each line in the code below are calling the program to execute.

Part 1:

int checkarray(int arr[],int size){

int count=0;

for(int i=0;i

if(isPrime(arr[i]) && Fib(arr[i]))

count++;

}

return count;

Part 2:

#include

#include

using namespace std;

bool isSquare(int x)

{

int s = sqrt(x);

return (s*s == x);

}

bool Fib(int n)

{

return isSquare(5*n*n + 4) ||

isSquare(5*n*n - 4);

}

bool isPrime(int n){

if (n <= 1)

return false;

for (int i = 2; i < n; i++)

if (n % i == 0)

return false;

return true;

}

int checkarray(int arr[],int size){

int count=0;

for(int i=0;i

if(isPrime(arr[i]) && Fib(arr[i]))

count++;

}

return count;

}

int main(){

int arr[9];

cout<<"Enter Number of elements 9"<

cin>>arr[0]>>arr[1]>>arr[2]>>arr[3]>>arr[4]>>arr[5]>>arr[6]>>arr[7]>>arr[8];

int size=(int)(sizeof arr)/(sizeof arr[0]);

cout<<"Number of elements that are both prime and fibonacci are "<

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!