(25 points) There are 900 people in a town whose population increases by 10 perc
ID: 3726700 • Letter: #
Question
(25 points) There are 900 people in a town whose population increases by 10 percent (a data item) each year. Write a loop that displays the annual population and determines how many years (countYears) it will take for the population to pass 20,000. Verify that your program works if the population doubles each year (an increase of 100%). 4. ear:-17-population T-453Z Year: 18 Population: 4985 Year: 19 Population: 5483 Year: 20 Population: 6031 Year: 21 Population: 6634 Year: 22 Population: 7297 Year: 23 Population: 8826 Year: 24 Population: 8828 Year: 25 Population: 9718 Year: 26 Population: 18681 Year: 27 Population: 11749 Year: 28 Population: 12923 Year: 29 Population: 14215 Year: 30 Population: 15636 Year: 31 Population: 17199 Year: 32 Population: 18918 Year: 33 Population: 28809 The Town will reach 20,e00 habitants at a growth of 10 in 33 yearsExplanation / Answer
Following is the c++ Program for 10% growth:
#include <iostream>
using namespace std;
int main() {
int people = 900;
int year = 0;
int sum = 0;
while(people<=20000){
sum = (people * 10)/100;
people = people + sum;
year+=1;
cout<<"Year: "<<year <<" Popolation: "<< people<< " ";
}
cout<<"The town will reach 20,000 habitants at a growth of 10 in " << year<< " years";
return 0;
}
Following is the same Program for 100% growth:
#include <iostream>
using namespace std;
int main() {
int people = 900;
int year = 0;
int sum = 0;
while(people<=20000){
sum = (people * 100)/100;
people = people + sum;
year+=1;
cout<<"Year: "<<year <<" Popolation: "<< people<< " ";
}
cout<<"The town will reach 20,000 habitants at a growth of 100 in " << year<< " years";
return 0;
}
output is:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.