Question: 1. Write a C function [int isPrime(int i)] that accepts as one parameter: an integer, and determines if it is a prime number. Return 0
1. Write a C function [int isPrime(int i)] that accepts as one parameter: an integer, and determines if it is a prime number. Return 0 if it is not and 1 if it is.
2. Write a C function [int isFib(int i)] that accepts an integer as a parameter and determines if it is a number from the Fibonacci sequence. Return 0 if it is not and 1 if it is.
Source code for 1 and 2 is -
1. isprime.c
int isPrime (int i){ int p; for(p=2; p<=i-1;p++) { if((i%p) == 0) { return 0; } } return 1; }
2. isfib.c
int isFib(int i){
int a = 0, b = 1, c;
while(b
c = a+b;
a = b;
b = c;
}
if(b==i)
return 1;
else
return 0;
}
3. Now, write a C program (show the source code and the screen captures for the test runs) that accepts two integer values x1 and x2 specifying the range of integers (all inclusive), and tests all the values in the specified range printing only the Fibonacci primes in this range. Use the functions defined in separate files isprime.c and isfib.c. Run the program twice on the range:
a. 10 to 100
b. 1597 to 1597
I have done 1 and 2. Please do question 3 and give comments in code for me to understand.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
