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
5. One of the major road blocks for direct DC power in residences is the ___. A) generation of DC B) lack of standardization C)
Montano1993 [528]

Answer:

D) quantity of components required for this type of system

Explanation:

Electricity can be transmitted using the alternating and direct currents. The alternating current is one in which the flow of the current diverts at certain time intervals whereas, the direct current is one in which there is a constant one-directional flow of current. The DC is used in batteries and solar panels. Residential areas and business places make use of the AC current.

One of the several reasons why the DC is not used in homes is because unlike the AC it is not easy to build and sustain. Moreso, it has more components compared to the AC. For example, its motor consists of brushes and commutators . The components, example, switches are also large compared to the AC components.

6 0
3 years ago
why is the peak value of the rectified output less than the peak value of the ac input and by how much g
Bumek [7]

Answer:

The Peak value of the output voltage is less or lower than that of the peak value of the input voltage by 0.6V reason been that the voltage is tend to drop across the diode.

Explanation:

This is what we called HALF WAVE RECTIFIER in which the Peak value of the output voltage is less or lower than that of the peak value of the input voltage by 0.6V reason been that the voltage is tend to drop across the diode.

Therefore this is the formula for Half wave rectifier

Vrms = Vm/2 and Vdc

= Vm/π:

Where,

Vrms = rms value of input

Vdc = Average value of input

Vm = peak value of output

Hence, half wave rectifier is a rectifier which allows one half-cycle of an AC voltage waveform to pass which inturn block the other half-cycle which is why this type of rectifiers are often been used to help convert AC voltage to a DC voltage, because they only require a single diode to inorder to construct.

5 0
3 years ago
Suppose the country of Bangladesh wants a low interest loan to invest in the building of infrastructure. Which international org
musickatia [10]

Answer:

C. UNDP or World Bank.

Explanation:

Suppose the country of Bangladesh wants a low interest loan to invest in the building of infrastructure. The international organizations which Bangladesh would most likely turn to are UNDP or World Bank.

3 0
3 years ago
1. When the pneumatic device was demonstrated, explain something that was different than what you expected.
Vera_Pavlovna [14]

Answer:

1. Effect of air pressure

2. air- powered wheel chair

3. Pneumatic valves

Explanation:

1. In any pneumatic device, the mipact of air pressure to produce the moving effect on an heavy object is unexpected.

2. pneumatice demultiplexer when air in comprressed tank is allowed released to cause movement of the  chair.

3. In industries, a pneumatic valve operates by force of air when actuated. A signal causes actuation of coil. When coil is energized, compressed high pressure air is allowe to enter in a small cylinder and cause operation of valve

5 0
3 years ago
Read 2 more answers
A search will start from a visual lead<br> true<br> false
BlackZzzverrR [31]
True

An organized searching process will need to start from the visual lead area. Eye focus and eye movements from the path of travel in an organized pattern describes a visual search process.
4 0
2 years ago
Read 2 more answers
Other questions:
  • Water flows down a rectangular channel that is 1.2 m wide and 1 m deep. The flow rate is 0.95 m/s. Estimate the Froude number of
    15·1 answer
  • Evan notices a small fire in his workplace. Since the fire is small and the atmosphere is not smoky he decides to fight the fire
    10·1 answer
  • How much time does it take a freezer to make a tray of ice cubes out of a tray of 0.25kg liquid water at 10 Celsius). Assume the
    13·1 answer
  • Atmospheric pressure is measured to be 14.769 psia. a. What would be the equivalent reading of a water barometer (inches of H20)
    11·1 answer
  • What fraction of the worlds surface is estimated to be arable land?
    15·1 answer
  • Are routers better for internet connection rather than a WiFi modem?
    6·2 answers
  • The specific gravity of a fluid with a weight density of 31.2 lb/ft is a. 2.00 b. 0.969 c. 0.500 d. 1.03
    10·1 answer
  • What is the definition of comma
    15·1 answer
  • Where loads are likely to be on continuously, the calculated load for branch circuits and feeders must be figured at (100%) (125
    6·1 answer
  • compressors, the gas is often cooled while being compressed to reduce the power consumed by the compressor. explain how cooling
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!