In: Electrical Engineering
The population of a town A is less than the population of town B. However, the population of town A is growing faster than the population of town B. Write a program that prompts the user to enter the population and growth rate of each town. The program outputs after how many years the population of town A will be greater than or equal to the population of town B and the populations of both the towns at that time. (A sample input is: Population of town A = 5000, growth rate of town A = 4%, population of town B = 8000, and growth rate of town B =2%.)
Hint: The population can be calculated as the following:
,??-????????????.=,??-??????????????.?(1+??????????? ????????/100.0)
here iam attached c language code and simulation results
#include<stdio.h>
main()
{
int pa,pb,pga,pgb; // declarations of intiger variables
int a,b,c=0;
printf("Note1 : papulation of town A less than town B\n");
printf("Note2: papulation of growth rate of town A gretter than
town B\n");
printf("enter papulation of town A:");
scanf("%d",&pa);
printf("enter growth rzte of town A: EX: 2 any intiger value
");
scanf("%d",&pga);
printf("enter papulation of town B :");
scanf("%d",&pb);
printf("enter growth rzte of town B: EX 2 intiger any rate value
");
scanf("%d",&pgb);
pga=pga*100; // growth rate converted to percentage
pgb=pgb*100; // growth rate converted to percentage
while(1) // infinate loop
{
a=pa*(1+pga/100); // calculate new papulation
b=pb*(1+pgb/100); // calculate new papulation
c=c+1; // count number of years
if (a>=b)
break;
else
{
pa=a;
pb=b;
}
}
printf(" number of years papulation of town a gretter than equal to
town b : %d",c);
getch();
}