Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program using that uses a for loop which loops three times and calls

ID: 3546817 • Letter: W

Question

Write a C++ program using that uses a for loop which loops three times and calls function int isleap (int) to return whether or not a year is a leap year. The result should be output in the main program. Next the main program should be a do while loop to call function void Fibonacci (int) tp produce the first n Fibonacci numbers. The function receives as an argument integer n and outputs all results within this function. Note that the set of Fibonacci numbers is a sequence of numbers that increase rapidly. They were originally intended to model the growth of a rabbit colony.

Explanation / Answer

#include<iostream>
using namespace std;
bool isleap(int year)
{
if(year%400 ==0 || (year%100 != 0 && year%4 == 0))
return true;
return false;
}
void Fibonacci(int n)
{
int a = 1;
int b = 1;
int c;
cout << a << endl;
cout << b << endl;
for(int i=2; i<n; i++)
{
c = a+b;
cout << c << endl;
a = b;
b =c;
}
}
int main()
{
int year[3];
cout <<"Enter three years:" << endl;
for(int i=0; i<3; i++)
{
cin >> year[i];
if(isleap(year[i]))
cout << year[i] << " is a leap year " << endl;
else
cout << year[i] << " is not a leap year " << endl;
}
int n;
cout <<"Enter n :";
cin >> n;
cout << endl;
do
{
Fibonacci(n);
}while(false);
//system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote