I need help with the following c program I found the answer

I need help with the following c++ program. I found the answer online but need some original work.

The following program is to be written with a loop. You are to write this program three times and each time with a different loop control structure (for loop, while and do-while). The Fibonacci numbers Fn are define as follows. F0 is 1, F1 is 1, and Fi = Fi-1 + Fi-2 for i = 0, 1, 2, 3, ... In other words, each number is the sum of the previous two integer numbers for F2. The first few Fibonacci numbers are 1, 1, 2, 3, 5, and 8. One place that these numbers occur is as certain population growth rates. If a population has no deaths, then the series shows the size of the population after each time period. It takes an organism two time periods to mature to reproducing age, and then the organism reproduces once every time period (thus the reason for two 1\'s before you start adding). The formula applies most straightforwardly to a sexual reproduction at a rate of one offspring per time period. Assume that the green crud population grows at this rate and has a time period of 10 days. Hence, if a green crud population starts out as 5 pounds of crud, then in 10 days there is still 5 pounds of crud; at the end of the next 10 days there is still 10 pounds of crud; in 10 more days we have 20 pounds (the sum of the previous two 10 day periods). The next 10 days will produce 30 pounds. Write a program that takes both the initial size of green crud population (in pounds) and a number of days as input, and output the number of pounds of green crud after that many days of growth. Assume that the population size is the same for 9 days and then increases every tenth day. Input to the crud program: start with 5 pounds of green crude and display the how much crude we have after 200 days. Run each of the three versions of the program with 200 days. You can NOT use arrays for this program.

Solution

for loop:

#include <iostream>
using namespace std;

int main()
{
   int initial_size,days,growth_in_days,population,i;
   initial_size = 5;
   cout<<\"Enter the number of days of growth\";
   cin>>days;
   growth_in_days = 5;
   for(i=1;i<days/10;i++)           //days is divided by growth interval ie 10
   {
       population = initial_size + growth_in_days;
       initial_size = growth_in_days;
       growth_in_days = population;
   }
  
   cout<<\"\ Population in \"<< days <<\" days :\"<< population;
   return 0;
}

output:

while loop:

#include <iostream>
using namespace std;

int main()
{
   int initial_size,days,growth_in_days,population,i;
   initial_size = 5;
   cout<<\"Enter the number of days of growth\";
   cin>>days;
   growth_in_days = 5;
   i=1;
   while(i<days/10)           //days is divided by growth interval ie 10
   {
       population = initial_size + growth_in_days;
       initial_size = growth_in_days;
       growth_in_days = population;
       i++;
   }
  
   cout<<\"\ Population in \"<< days <<\" days :\"<< population;
   return 0;
}

output:

do while loop :

#include <iostream>
using namespace std;

int main()
{
   int initial_size,days,growth_in_days,population,i;
   initial_size = 5;
   cout<<\"Enter the number of days of growth\";
   cin>>days;
   growth_in_days = 5;
   i=1;
   do
   {
       population = initial_size + growth_in_days;
       initial_size = growth_in_days;
       growth_in_days = population;
       i++;
   }while(i<days/10);           //days is divided by growth interval ie 10
  
   cout<<\"\ Population in \"<< days <<\" days :\"<< population;
   return 0;
}

output:

I need help with the following c++ program. I found the answer online but need some original work. The following program is to be written with a loop. You are t
I need help with the following c++ program. I found the answer online but need some original work. The following program is to be written with a loop. You are t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site