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
The purpose of daytime running lights (DRLs) is to _____.
balu736 [363]
D make your car easy to spot in daytime because they do not illuminate a lot
3 0
4 years ago
Read 2 more answers
Is EPA is the organization that was formed to ensure safe and health working conditions for workers by setting and enforcing sta
mr_godi [17]
Let me search this up
3 0
2 years ago
Today I meant to look for my missing watch, but I could never find the time.
xxMikexx [17]

Answer:

haha i get it

Explanation:

5 0
3 years ago
Read 2 more answers
An iron-carbon alloy initially containing 0.286 wt% C is exposed to an oxygen-rich and virtually carbon-free atmosphere at 1200°
Fantom [35]

Answer:

Explanation:

Given data:

initial construction co = 0.286 wt %

concentration at surface position cs = 0 wt %

carbon concentration cx = 0.215 wt%

time = 7 hr

D =  7.5 \times 10^{-11} m^2/s

for 0.225% carbon concentration following formula is used

\frac{cx -co}{cs -co} = 1 - erf(\frac{x}{2\sqrt{DT}})

where, erf stand for error function

\frac{cx -co}{cs -co} = \frac{0.215 -0.286}{0 -0.286} =0.248

0.248 = 1 - erf(\frac{x}{2\sqrt{DT}})

erf(\frac{x}{2\sqrt{DT}}) = 1 - 0.248

erf(\frac{x}{2\sqrt{DT}}) = 0.751

from the table erf(Z) value = 0.751 lie between (z) = 0.80 and z = 0.85 so by inteerpolation we have z = 0.815

from given table

\frac{x}{2\sqrt{DT}} = 0.815

x = 2\times 0.815 \times \sqrt{7.5 \times 10^{-11}\times (7\times 3600)

x = 2.39\times 10^{-3} m

x = 0.002395 mm

8 0
3 years ago
A 14 inch diameter pipe is decreased in diameter by 2 inches through a contraction. The pressure entering the contraction is 28
Delicious77 [7]

Answer:

5984.67N

Explanation:

A 14 inch diameter pipe is decreased in diameter by 2 inches through a contraction. The pressure entering the contraction is 28 psi and a pressure drop of 2 psi occurs through the contraction if the upstream velocity is 4.0 ft/sec. What is the magnitude of the resultant force (lbs) needed to hold the pipe in place?

from continuity equation

v1A1=v2A2

equation of continuity

v1=4ft /s=1.21m/s

d1=14 inch=.35m

d2=14-2=0.304m

A1=pi*d^2/4

0.096m^2

a2=0.0706m^2

from continuity once again

1.21*0.096=v2(0.07)

v2=1.65

force on the pipe

(p1A1- p2A2) + m(v2 – v1)

from bernoulli

p1 + ρv1^2/2 = p2 + ρv2^2/2

difference in pressure or pressure drop

p1-p2=2psi

13.789N/m^2=rho(1.65^2-1.21^2)/2

rho=21.91kg/m^3

since the pipe is cylindrical

pressure is egh

13.789=21.91*9.81*h

length of the pipe is

0.064m

AH=volume of the pipe(area *h)

the mass =rho*A*H

0.064*0.07*21.91

m=0.098kg

(193053*0.096- 179263.6* 0.07) + 0.098(1.65 – 1.21)

force =5984.67N

4 0
3 years ago
Other questions:
  • A thin‐walled tube with a diameter of 12 mm and length of 25 m is used to carry exhaust gas from a smoke stack to the laboratory
    10·1 answer
  • Write the following statements as Prolog clauses, in the order given: If it is raining or snowing, then there is precipitation.
    15·1 answer
  • Zionjasean17 zionjasean17
    8·2 answers
  • Which of the following describes a product concept?
    15·1 answer
  • Ohm's law states that the current (I) in amps equals the voltage (E) in volts decided by the resistance (R) in ohm's. If you con
    15·1 answer
  • Answer the following questions about your own experience in the labor force.
    15·1 answer
  • Shane's 100-watt radio draws 7 amps of current on a 120-volt circuit. What is the resistance in the radio?
    8·1 answer
  • Who is the strongest avenger i say hulk but who knows at this point
    7·2 answers
  • 40 POINTS IF ANSERED WITHIN 10 MINS
    13·2 answers
  • assuming complementary inputs are available, the minimum number of transistors needed to realize a two input xor gate is:
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!