The country A has 50M inhabitants, and its population grows 3% per year. The country B, 70M and grows 2% per year. Tell in how many years A will surpass B.
#include <stdio.h>
int main()
{
constint A_GROWTH_RATE = 3;
constint B_GROWTH_RATE = 2;
constint A_POPULATION = 50; //MILS
constint B_POPULATION = 70; //MILS
float a_pop_curr = A_POPULATION;
float b_pop_curr = B_POPULATION;
int years = 0;
while(a_pop_curr <= b_pop_curr)
{
a_pop_curr += a_pop_curr*(A_GROWTH_RATE/100);
b_pop_curr += b_pop_curr*(B_GROWTH_RATE/100);
years++;
}
printf("After %d years, A will have a population of %.2f while B will have a population of %.2f", years, a_pop_curr, b_pop_curr);
return 0;
}