write a program that asks the user for a non-negative positive number greater than 1. The user is re-prompted to enter a valid number if a number less than 1 is entered. The program then outputs: (a) the largest Fibonacci number that is less than or equal to the input and (b) the largest prime number less than or equal to the input.
(a) you must define 3-4 appropriate functions, (b) write proper comments describing critical aspects of your logic and reasoning, (c ), must be accurate.
so far i have:
#include <iostream>
using namespace std;
int fib(int n) // calls fibonacci function
{
if(1 == n || 2 == n)
{
return 1;
}
else
{
return fib(n-1) + fib(n-2);// adds previous fibonacci numbers
}
}
int prime(int k)
{
if (k % 2 == 0|| k % 3 == 0 || k % 5 == 0 )
return k;
}
int main() {
int i;
cout<< "Please enter an integer (number must be greater than 1):"<< endl;
cin>> i;
if( i==1) {
cout<< " Please enter another number"<< endl;
}
else {
cout <<"the closest fibonacci number is" <<fib(i) << endl;//prints fibonacci number
}
cout << " the closest prime number is" << prime(i)<< endl;
Fibonnaci number is a number in the sequence 1, 1, 2, 3, 5, 8, 13, 21, etc. where the next number in the sequence is the sum of the last two numbers (1+1 = 2, 1+2 = 3, 2+3 = 5, 3+5 =8, 5+8=13, 8+13 = 21, etc)