SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
More Flow Of Control
Exercise:
Programming Projects
Question:10 | ISBN:9780321531346 | Edition: 7

Question

The Fibonacci numbers Fn are defined as follows. F0 is 1, F1 is 1, and Fi+2 = Fi + Fi + 1 i = 0, 1, 2, … . In other words, each number is the sum of the previous two 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. The formula applies most straightforwardly to asexual 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 5 days. Hence, if a green crud population starts out as 10 pounds of crud, then in 5 days there is still 10 pounds of crud; in 10 days there is 20 pounds of crud, in 15 days 30 pounds, in 20 days 50 pounds, and so forth. Write a program that takes both the initial size of a green crud population (in pounds) and a number of days as input, and that outputs the number of pounds of green crud after that many days.

Assume that the population size is the same for four days and then increases every fifth day. Your program should allow the user to repeat this calculation as often as desired.desired.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer



#include
using namespace std;
void main()
{
	int pop, days, prevpop;
	char choice;
	do	
	{
		cout<<"\n Enter initial curd popuplation: " ;
		cin>>pop;
     	cout<<"\nEnter number of days: ";
		cin>> days;
		days = days/5;
		if(days<=2)
		{
			cout<<" Population will remain same"<>choice;
	}while(choice =='y' || choice =='Y');
	system("pause");
}

Output:

Enter initial curd popuplation: 50000
Enter number of days: 20
Population: 100010

To continue  then enter Y:n
0 0

Discussions

Post the discussion to improve the above solution.