1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yarga [219]
3 years ago
7

C++ - Green Crud Fibonacci programThe 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+2 = Fi + Fi+1 for i = 0, 1, 2, 3, ... In other words, each number is the sum of the previous two integer numbers. 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 10 pounds of crud; in 20 days 10 pounds (the sum of the previous two 10 day periods). 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.Now, what happens when you run the program for 225 days when you use the simple data type ‘int’? (Not long int or double ect.)
Engineering
1 answer:
Fynjy0 [20]3 years ago
7 0

Answer:

Below is the required code:

Explanation:

Using for loop

#include <iostream>

using namespace std;

int main()

{

    //Initial crud size

    int init = 0;

    int newCrud;

    int next=0;

    //Number of days to simulate

    int no_days;

    int day;

    cout << "Enter initial amount of green crud: ";

    cin >> newCrud;

    cout << "Enter number of days to simulate: ";

    cin >> no_days;

    for (day = 10; day<=no_days; day++)

    {

         if (day % 10 == 0)

         {

             next = newCrud + init;

         }

             newCrud = init;

             init = next;

    }

    if (no_days < 5)

    cout << "\nCrud reproduce only after 5 days minimum.Hence the current amount is "

    << newCrud << " pounds.";

    else

    cout << "On day " << no_days << " you have " << init

    << " pounds of green crud." << endl;

    cout << "\nWould you like to continue? (y or n): ";

    cin >> ans;

         return 0;

}

Output:

         Enter initial amount of green crud: 5

         Enter number of days to simulate: 220

    On day 220 you have 10485760 pounds of green crud.

Using while loop

Program:

#include <iostream>

using namespace std;

int main()

{

    char ans='y';

    while (ans == 'Y' || ans == 'y')

    {

         //Initial crud size

         int init = 0;

         int newCrud;

         int next=0;

         //Number of days to simulate

         int no_days;

         int day;

         cout << "Enter initial amount of green crud:

         ";

         cin >> newCrud;

         cout << "Enter number of days to simulate:

         ";

         cin >> no_days;

         for (day = 10; day<=no_days; day++)

         {

             if (day % 10 == 0)

             {

                  next = newCrud + init;

             }

                  newCrud = init;

                  init = next;

         }

         if (no_days < 5)

         cout << "\nCrud reproduce only after 5 days

         minimum.Hence the current amount is "

         << newCrud << " pounds.";

         else

         cout << "On day " << no_days << " you have "

         << init

         << " pounds of green crud." << endl;

         cout << "\nWould you like to continue? (y or

         n): ";

         cin >> ans;

    }

    return 0;

}

Output:

Enter initial amount of green crud: 5

Enter number of days to simulate: 220

On day 220 you have 10485760 pounds of green crud.

Would you like to continue? (y or n): y

Enter initial amount of green crud: 5

Enter number of days to simulate: 225

On day 225 you have 10485760 pounds of green crud.

Using do while loop

Program:

#include <iostream>

using namespace std;

int main()

{

    char ans;

    do

    {

         //Initial crud size

         int init = 0;

         int newCrud;

         int next=0;

         //Number of days to simulate

         int no_days;

         int day;

         cout << "Enter initial amount of green crud: ";

         cin >> newCrud;

         cout << "Enter number of days to simulate: ";

         cin >> no_days;

         for (day = 10; day<=no_days; day++)

         {

             if (day % 10 == 0)

             {

                  next = newCrud + init;

             }

                  newCrud = init;

                  init = next;

         }

         if (no_days < 5)

         cout << "\nCrud reproduce only after 5 days

         minimum.Hence the current amount is "

         << newCrud << " pounds.";

         else

         

         cout << "On day " << no_days << " you have " <<

         init << " pounds of green crud." << endl;

         cout << "\nWould you like to continue? (y or n):

         ";

         cin >> ans;

    } while (ans == 'Y' || ans == 'y');

    return 0;

}

Output:

Enter initial amount of green crud: 5

Enter number of days to simulate: 220

On day 220 you have 10485760 pounds of green crud.

Would you like to continue? (y or n): y

Enter initial amount of green crud: 5

Enter number of days to simulate: 225

On day 225 you have 10485760 pounds of green crud.

You might be interested in
State the number of terms for each of the following algebraic expression 2x+1
harina [27]

Answer:

Expressions are made up of terms.

A term is a product of factors.

Coefficient is the numerical factor in the term

Before moving to terms like monomials, binomials, and polynomials, like and unlike terms are discussed.

When terms have the same algebraic factors, they are like terms.

When terms have different algebraic factors, they are unlike terms.

Explanation:

Hi please follow me also if you can and thanks.

6 0
3 years ago
The increasing interconnections of peoples and countries around the world is known as ________.
Irina18 [472]
I think it’s rationalization.
Hope this helps
4 0
3 years ago
Read 2 more answers
A(n) ______ is used to measure fluid flow in engineering
Arte-miy333 [17]

Answer:

A pitot tube is used to measure fluid flow in engineering

3 0
2 years ago
Relay contacts that are defined as being normally open (n.o.) have contacts that are:_____.
Reptile [31]

Relay contacts that are defined as being normally open (n.o.) have contacts that are open only if  the relay coil is known to have de-energized.

<h3>What is meant by normally open contacts?</h3>

Normally open (NO) are  known to be open if there is no measure of current that is flowing through a given coil but it often close as soon as the coil is said to be energized.

Note that  Normally closed (NO) contacts are said to be closed only if the coil is said to be de-energized and open only if the coil is said to carry current or is known to have energized.

The role of relay contact is wide. The Relays are tools that are often used in the work of  switching of control circuits and it is one that  a person cannot used for power switching that has relatively bigger ampacity.

Therefore, Relay contacts that are defined as being normally open (n.o.) have contacts that are open only if  the relay coil is known to have de-energized.

Learn more about Relay contacts from

brainly.com/question/15334861
#SPJ1

8 0
1 year ago
Pls follow me in brainly​
Sergio [31]

Answer:

sure

Add on:

!!

5 0
3 years ago
Read 2 more answers
Other questions:
  • Question Set 22.1 Using the count method, find the number of occurrences of the character 's' in the string 'mississippi'.2.2 In
    10·1 answer
  • ‏What is the potential energy in joules of a 12 kg ( mass ) at 25 m above a datum plane ?
    7·1 answer
  • Consider a sinusoidal oscillator consisting of an amplifier having a frequency-independent gain A (where A is positive) and a se
    6·1 answer
  • The diameter of an extruder barrel = 85 mm and its length = 2.00 m. The screw rotates at 55 rev/min, its channel depth = 8.0 mm,
    5·1 answer
  • You are a technical writer for Landson Toy Company. Landson has just designed a new, more durable swing set for 6- to 10-year-ol
    9·1 answer
  • Thin film deposition is a process where: a)-elemental, alloy, or compound thin films are deposited onto a bulk substrate! b)-Pho
    12·1 answer
  • A train travels 650 meters in 25 seconds. What is the train's velocity?
    9·1 answer
  • I really need help i will give brainly plz no funny answers
    14·1 answer
  • 2) What kinds of food can you eat in space?
    14·2 answers
  • The Environmental Protection Agency (EPA) has standards and regulations that says that the lead level in soil cannot exceed the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!