Title: Ancient Population v1
1// Ancient Population v1 // It follows latest GPL
// Made by James Leigh, crinje_at_gnu.com
// ancient.population birth number
unproductive number survival number
// - birth sets the interval of births (5 means
one son and one daughter were born in every five
years) // - unproductive sets the unproductive ye
ars. (50 means they did not give birth for the
last 50 years in their lives) // - survival sets
the survival rates. 6 means 6 out of 10 new born
babies survived. survival rate 100 - mortality
rate. include ltstdio.hgt include ltstring.hgt int
gen_calc(unsigned short int birth_interval,
float survival_rate, unsigned short int
unproductive_years) int init_table(void) int exp
ort2csv(unsigned short int birth_interval, float
survival_rate, unsigned short int
unproductive_years) unsigned long long int gen1
61657 unsigned short int g7_end const int g1
_start 0, g1_end 930, g2_start 130, g2_end
1042 const int g3_start 235, g3_end 1140, g
4_start 325, g4_end 1235 const int g5_start
395, g5_end 1290, g6_start 460, g6_end
1422 const int g7_start 622, g8_start 687, g8
_end 1656 const int g9_start 874, g9_end 16
51 const int g10_start 1056, g11_start 1173,
g12_start 1290, g13_start 1407, g14_start
1524, g15_start 1641 const int flood 1656, en
och 987 int main(int argc, char argv) i
nt temp, year float survival_rate 50 unsigne
d short int birth_interval 10
unsigned short int unproductive_years 50
printf("Calculating the ancient polulation
before the great flood.\n\n") if (argc ! 1
argc ! 3 argc ! 5 argc ! 7)
printf("Wrong commandline arguement number.\n
Exiting programme.\n") return 1 if (argc
1) printf("No value input. Using default v
alues...\n\n") else for (temp argc - 2 t
emp gt 1 temp temp - 2) if ((strncmp(arg
vtemp, "birth", strlen(argvtemp))) 0)
printf("Taking birth interval value...\n"
) birth_interval atoi(argvtemp 1)
else if ((strncmp(argvtemp, "unproductive",
strlen(argvtemp))) 0) printf("Taking
unproductive years value...\n")
unproductive_years atoi(argvtemp 1)
else if ((strncmp(argvtemp, "survival",
strlen(argvtemp))) 0) printf("Taking
survival rate value...\n") survival_rate a
toi(argvtemp 1) else printf(
"Commandline arguement is not correct.\nExiting
programme\n") return 1 printf("\t
Assumes that dc of new born babies
survived.\n", (int)survival_rate, '')
printf("\tAssumes that the parents gave birth to
two kids in every d years.\n", birth_interval)
printf("\tAssumes that the last d years in
life, they did not produce any offspring.\n\n",
unproductive_years) survival_rate survival_rat
e / 100 g7_end g7_start 912 birth_interval
printf("Initialising the generation table...")
init_table() printf(" Done\n\n") //Call sp
ecial condition function gen_calc(birth_interval,
survival_rate, unproductive_years)
export2csv(birth_interval, survival_rate,
unproductive_years) int gen_calc(unsigned shor
t int birth_interval, float survival_rate,
unsigned short int unproductive_years)
unsigned int year, temp_mod, temp_year print
f("Calculating the population of 1st
generation...\n") printf("\tYear d Adam create
d...\n", g1_start) for (year g1_start year lt
g1_end year) gen1year 2 printf("\tYe
ar d Adam died...\n", g1_end)
printf("Done.\n\n") printf("Calculating the po
pulation of 2nd generation...\n")
printf("\tYear d Adam gave birth to
Seth...\n", g2_start) for (year g2_start, temp
_mod year - birth_interval year lt (g1_end -
unproductive_years) year) if (((year - temp_m
od) birth_interval) 0) gen2year gen
2year - 1 gen1year else gen2year
gen2year -1 printf("\tYear d Adam stop
ped produing...\n", g1_end - unproductive_years)
for (year g1_end - unproductive_years 1
year lt (g2_end - 1) year) gen2year gen
2year-1 printf("\tYear d Seth died...\n",
g2_end) for (year g2_end, temp_mod year - bi
rth_interval year lt flood year)
if (((year - temp_mod) birth_interval) 0)
gen2year gen2year - 1 - gen2year
- (g2_end - g2_start) gen2year - (g2_end -
g2_start) - birth_interval else gen2year
gen2year - 1 printf("Done.\n\n") prin
tf("Calculating the population of 3rd
generation...\n") printf("\tYear d Seth gave b
irth to Enos...\n", g3_start) for (year g3_sta
rt, temp_mod year - birth_interval year lt
(g2_end - unproductive_years) year)
if (((year - temp_mod) birth_interval) 0)
gen3year gen3year - 1 gen2year
- (g3_start - g2_start) survival_rate
else gen3year gen3year - 1 printf
("\tYear d Adam's last son began
producing...\n", g1_end - unproductive_years
g3_start - g2_start) printf("\tYear d Seth sto
pped producing...\n", g2_end - unproductive_years)
for (year g2_end - unproductive_years 1, te
mp_mod year - birth_interval, temp_year year
- g2_start year lt g2_end - 1 year)
if (((year - temp_mod) birth_interval) 0)
gen3year gen3year - 1 (gen2year
- (g3_start - g2_start) - gen2year -
temp_year) survival_rate else gen3yea
r gen3year - 1 for (year g2_end, temp_m
od year - birth_interval year lt g3_end - 1
year) if (((year - temp_mod) birth_interval)
0) gen3year gen3year - 1 (gen2
year - (g3_start - g2_start) - gen2year -
temp_year gen2year - (g2_end - g2_start))
survival_rate else gen3year gen3
year - 1 printf("\tYear 1140 Enos died...\n")
for (year g3_end, temp_mod year -
birth_interval year lt flood year)
if (((year - temp_mod) birth_interval) 0)
gen3year gen3year - 1 (gen2year
- (g3_start - g2_start) - gen2year -
temp_year gen2year - (g2_end - g2_start))
survival_rate - (gen3year - (g3_end -
g3_start) - gen3year - (g3_end - g3_start) -
birth_interval) else gen3year gen3
year - 1 printf("Done.\n\n") printf("Calcula
ting the population of 4th generation...\n")
printf("\tYear d Enos gave birth to
Cainan...\n", g4_start) for (year g4_start, te
mp_mod year - birth_interval year lt (g3_end -
unproductive_years) year) if (((year - temp_m
od) birth_interval) 0) gen4year gen
4year - 1 gen3year - (g4_start -
g3_start) survival_rate else gen4year
gen4year - 1 printf("\tYear d Enos stop
ped producing...\n", g3_end - unproductive_years)
for (year g3_end - unproductive_years 1,
temp_mod year - birth_interval, temp_year
year - g3_start year lt g3_end - 1 year)
if (((year - temp_mod) birth_interval) 0)
gen4year gen4year - 1 (gen3year
- (g4_start - g3_start) - gen3year -
temp_year) survival_rate else gen4yea
r gen4year - 1 for (year g3_end, temp_m
od year - birth_interval year lt g4_end - 1
year) if (((year - temp_mod) birth_interval)
0) gen4year gen4year - 1 (gen3
year - (g4_start - g3_start) - gen3year -
temp_year gen3year - (g3_end - g3_start))
survival_rate else gen4year gen4y
ear - 1 printf("\tYear d Cainan died...\n", g
4_end) for (year g4_end, temp_mod year - tem
p_mod year lt flood year) if (((year - temp_
mod) birth_interval) 0) gen4year gen
4year - 1 (gen3year - (g4_start -
g3_start) - gen3year - temp_year
gen3year - (g3_end - g3_start))
survival_rate - (gen4year - (g3_end -
g3_start) - gen4year - (g3_end - g3_start) -
birth_interval) else gen4year gen4
year - 1 printf("Done.\n\n") printf("Calcula
ting the population of 5th generation...\n")
printf("\tYear d Cainan gave birth to
Mahalaleel...\n", g5_start) for (year g5_start
, temp_mod year - birth_interval year lt
(g4_end - unproductive_years) year)
if (((year - temp_mod) birth_interval) 0)
gen5year gen5year - 1 gen4year
- (g5_start - g4_start) survival_rate
else gen5year gen5year - 1 printf
("\tYear d Cainan stopped producing...\n",
g4_end - unproductive_years) for (year g4_end
- unproductive_years 1, temp_mod year -
birth_interval, temp_year year - g4_start year
lt g4_end - 1 year) if (((year - temp_mod)
birth_interval) 0) gen5year gen5yea
r - 1 (gen4year - (g5_start - g4_start) -
gen4year - temp_year) survival_rate
else gen5year gen5year - 1 for (
year g4_end, temp_mod year - birth_interval
year lt g5_end - 1 year) if (((year - temp_mo
d) birth_interval) 0) gen5year gen5
year - 1 (gen4year - (g5_start -
g4_start) - gen4year - temp_year
gen4year - (g4_end - g4_start))
survival_rate else gen5year gen5yea
r - 1 printf("\tYear d Mahalaleel died...\n",
g5_end) for (year g5_end, temp_mod year - t
emp_mod year lt flood year)
if (((year - temp_mod) birth_interval) 0)
gen5year gen5year - 1 (gen4year
- (g5_start - g4_start) - gen4year -
temp_year gen4year - (g4_end - g4_start))
survival_rate - (gen5year - (g4_end -
g4_start) - gen5year - (g4_end - g4_start) -
birth_interval) else gen5year gen5
year - 1 printf("Done.\n\n") printf("Calcula
ting the population of 6th generation...\n")
printf("\tYear d Mahalaleel gave birth to
Jared...\n", g6_start) for (year g6_start, tem
p_mod year - birth_interval year lt (g5_end -
unproductive_years) year) if (((year - temp_m
od) birth_interval) 0) gen6year gen
6year - 1 gen5year - (g6_start -
g5_start) survival_rate else gen6year
gen6year - 1 printf("\tYear d Mahalalee
l stopped producing...\n", g5_end -
unproductive_years) for (year g5_end - unprodu
ctive_years 1, temp_mod year -
birth_interval, temp_year year - g5_start year
lt g5_end - 1 year) if (((year - temp_mod)
birth_interval) 0) gen6year gen6yea
r - 1 (gen5year - (g6_start - g5_start) -
gen5year - temp_year) survival_rate
else gen6year gen6year - 1 for (
year g5_end, temp_mod year - birth_interval
year lt g6_end - 1 year) if (((year - temp_mo
d) birth_interval) 0) gen6year gen6
year - 1 (gen5year - (g6_start -
g5_start) - gen5year - temp_year
gen5year - (g5_end - g5_start))
survival_rate else gen6year gen6yea
r - 1 printf("\tYear d Jared died...\n", g6_e
nd) for (year g6_end, temp_mod year - temp_m
od year lt flood year) if (((year - temp_mod
) birth_interval) 0) gen6year gen6
year - 1 (gen5year - (g6_start -
g5_start) - gen5year - temp_year
gen5year - (g5_end - g5_start))
survival_rate - (gen6year - (g5_end -
g5_start) - gen6year - (g5_end - g5_start) -
birth_interval) else gen6year gen6
year - 1 printf("Done.\n\n") printf("Calcula
ting the population of 7th generation...\n")
printf("\tYear d Jared gave birth to
Enoch...\n", g7_start) for (year g7_start, tem
p_mod year - birth_interval year lt (g6_end -
unproductive_years) year) if (((year - tem
p_mod) birth_interval) 0) gen7year g
en7year - 1 gen6year - (g7_start -
g6_start) survival_rate else gen7year
gen7year - 1 if (year enoch) g
en7year gen7year - 2
printf("\tYear d Enoch was taken up to
Heaven...\n", enoch) printf("\tYear d J
ared stopped producing...\n", g6_end -
unproductive_years) for (year g6_end - unprodu
ctive_years 1, temp_mod year -
birth_interval, temp_year year - g6_start year
lt g6_end - 1 year) if (((year - temp_mod)
birth_interval) 0) gen7year gen7yea
r - 1 (gen6year - (g7_start - g6_start) -
gen6year - temp_year) survival_rate
else gen7year gen7year - 1 for (
year g6_end, temp_mod year - birth_interval
year lt g7_end - 1 year) if (((year - temp_mo
d) birth_interval) 0) gen7year gen7
year - 1 (gen6year - (g7_start -
g6_start) - gen6year - temp_year
gen6year - (g6_end - g6_start))
survival_rate else gen7year gen7yea
r - 1 printf("\tYear d Second son of Jared di
ed (assumption)...\n", g7_end)
for (year g7_end, temp_mod year - temp_mod
year lt flood year) if (((year - temp_mod)
birth_interval) 0) gen7year gen7yea
r - 1 (gen6year - (g7_start - g6_start) -
gen6year - temp_year gen6year - (g6_end
- g6_start)) survival_rate - (gen7year -
(g6_end - g6_start) - gen7year - (g6_end -
g6_start) - birth_interval) else gen7yea
r gen7year - 1 printf("Done.\n\n") pri
ntf("Calculating the population of 8th
generation...\n") printf("\tYear d Enoch gave
birth to Methuselah...\n", g8_start)
for (year g8_start, temp_mod year -
birth_interval year lt (g7_end -
unproductive_years) year) if (((year - temp_m
od) birth_interval) 0) gen8year gen
8year - 1 gen7year - (g8_start -
g7_start) survival_rate else gen8year
gen8year - 1 printf("\tYear d Jared's s
econd son stopped producing(assumption)...\n",
g7_end - unproductive_years) for (year g7_end
- unproductive_years 1, temp_mod year -
birth_interval, temp_year year - g7_start year
lt g7_end - 1 year) if (((year - temp_mod)
birth_interval) 0) gen8year gen8yea
r - 1 (gen7year - (g8_start - g7_start) -
gen7year - temp_year) survival_rate
else gen8year gen8year - 1 for (
year g7_end, temp_mod year - birth_interval
year lt g8_end - 1 year) if (((year - temp_mo
d) birth_interval) 0) gen8year gen8
year - 1 (gen7year - (g8_start -
g7_start) - gen7year - temp_year
gen7year - (g7_end - g7_start))
survival_rate else gen8year gen8yea
r - 1 printf("Done.\n\n") printf("Calculatin
g the population of 9th generation...\n")
printf("\tYear d Methuselah gave birth to
Lamech...\n", g9_start) for (year g9_start, te
mp_mod year - birth_interval year lt (g8_end -
unproductive_years) year) if (((year - temp_m
od) birth_interval) 0) gen9year gen
9year - 1 gen8year - (g9_start -
g8_start) survival_rate else gen9year
gen9year - 1 printf("\tYear d Methusela
h stopped producing...\n", g8_end -
unproductive_years) for (year g8_end - unprodu
ctive_years 1, temp_mod year -
birth_interval, temp_year year - g8_start year
lt g8_end - 1 year) if (((year - temp_mod)
birth_interval) 0) gen9year gen9yea
r - 1 (gen8year - (g9_start - g8_start) -
gen8year - temp_year) survival_rate
else gen9year gen9year - 1 for (
year g8_end, temp_mod year - birth_interval
year lt g9_end - 1 year) if (((year - temp_mo
d) birth_interval) 0) gen9year gen9
year - 1 (gen8year - (g9_start -
g8_start) - gen8year - temp_year
gen8year - (g8_end - g8_start))
survival_rate else gen9year gen9yea
r - 1 printf("\tYear d Lamech died...\n", g9_
end) for (year g9_end, temp_mod year - temp_
mod year lt flood year) if (((year - temp_mo
d) birth_interval) 0) gen9year gen9
year - 1 (gen8year - (g9_start -
g8_start) - gen8year - temp_year
gen8year - (g8_end - g8_start))
survival_rate - (gen9year - (g8_end -
g8_start) - gen9year - (g8_end - g8_start) -
birth_interval) else gen9year gen9
year - 1 printf("Done.\n\n") printf("Calcula
ting the population of 10th generation...\n")
printf("\tYear d Lamech gave birth to
Noah...\n", g10_start) for (year g10_start, te
mp_mod year - birth_interval year lt flood
year) if (((year - temp_mod) birth_interv
al) 0) gen10year gen10year - 1 g
en9year - (g10_start - g9_start)
survival_rate else gen10year gen10y
ear - 1 if (year g10_start 500) ge
n10year gen10year 3
printf("\tYear d Noah gave birth to his
three sons...\n", g10_start 500)
printf("Done.\n\n") printf("Calculatin
g the population of 11th generation...\n")
printf("\tYear d Eldest one of 11th generation
gave his first birth to his kid(assumption)...\n",
g11_start) for (year g11_start, temp_mod ye
ar - birth_interval year lt flood year)
if (((year - temp_mod) birth_interval) 0)
gen11year gen11year - 1
gen10year - (g11_start - g10_start)
survival_rate else gen11year gen11y
ear - 1 printf("Done.\n\n") printf("Calculat
ing the population of 12th generation...\n")
printf("\tYear d Eldest one of 12th generation
gave his first birth to his kid(assumption)...\n",
g12_start) for (year g12_start, temp_mod ye
ar - birth_interval year lt flood year)
if (((year - temp_mod) birth_interval) 0)
gen12year gen12year - 1
gen11year - (g12_start - g11_start)
survival_rate else gen12year gen12y
ear - 1 printf("Done.\n\n") printf("Calculat
ing the population of 13th generation...\n")
printf("\tYear d Eldest one of 13th generation
gave his first birth to his kid(assumption)...\n",
g13_start) for (year g13_start, temp_mod ye
ar - birth_interval year lt flood year)
if (((year - temp_mod) birth_interval) 0)
gen13year gen13year - 1
gen12year - (g13_start - g12_start)
survival_rate else gen13year gen13y
ear - 1 printf("Done.\n\n") printf("Calculat
ing the population of 14th generation...\n")
printf("\tYear d Eldest one of 14th generation
gave his first birth to his kid(assumption)...\n",
g14_start) for (year g14_start, temp_mod ye
ar - birth_interval year lt flood year)
if (((year - temp_mod) birth_interval) 0)
gen14year gen14year - 1
gen13year - (g14_start - g13_start)
survival_rate else gen14year gen14y
ear - 1 printf("Done.\n\n") printf("Calculat
ing the population of 15th generation...\n")
printf("\tYear d Eldest one of 15th generation
gave his first birth to his kid(assumption)...\n",
g15_start) for (year g15_start, temp_mod ye
ar - birth_interval year lt flood year)
if (((year - temp_mod) birth_interval) 0)
gen15year gen15year - 1
gen14year - (g15_start - g14_start)
survival_rate else gen15year gen15y
ear - 1 printf("Done.\n\n") printf("Setting
the Flood year...") for (year 1 year lt 15 y
ear) genyearflood 0 gen10flood 2
gen11flood 6 printf("Done.\n\n") pri
ntf("Adding up the generations...")
for (year 0 year lt flood year)
for (temp_mod 1 temp_mod lt 15 temp_mod)
gen0year gen0year
gentemp_modyear printf("Done.\n\n") retur
n 0 int init_table(void) int temp, year f
or (temp 0 temp lt 15 temp)
for (year 0 year lt 1656 year)
gentempyear 0 return 0 int export2c
sv(unsigned short int birth_interval, float
survival_rate, unsigned short int
unproductive_years) FILE fp unsigned short i
nt year, temp fp fopen("Ancient.population.csv
", "w") fprintf(fp, "Ancient Population Calcula
tion Result by James Leigh\n")
fprintf(fp, "Assumes that dc of new born
babies survived.\n", (int)(survival_rate 100),
'') fprintf(fp, "Assumes that the parents gave
birth to two kids in every d years.\n",
birth_interval) fprintf(fp, "Assumes that they d
id not produce any offsprings for the last d
years in life.\n\n", unproductive_years)
fprintf(fp, "Year, Total") for (temp 1
temp lt 15 temp) fprintf(fp, ", Gen d", temp
) fprintf(fp, "\n") for (year 0 year lt fl
ood year) fprintf(fp, "d", year) for (
temp 0 temp lt 15 temp) fprintf(fp, ", l
ld", gentempyear) fprintf(fp, "\n") f
close(fp) return 0