In case the growth is increasing from the start and at some point starts to decrease you declare the var outside of the loop like int maxGrowth = 0; and at each iteration of loop compare this var with current growth. In case current growth is greater than maxGrowth you save current one into maxGrowth. Else in case maxGrowth is greater than current one the population has started to decrease and maxGrowth contains the maximum.
Btw, your function is in trouble: because n == 0 (always) - hence the loop will not iterate at all and function will always return 0. Also are you sure the t needs to be incremented twice per each loop iteration - in for() and in loop body? And in function growth you did not initialize var growth: and in case temp == 37 which value will be in growth?
Function to calculate the rate of change of the k Initial value for the k is 0.1 And with every generation k will be icreased by the value calculated in calculate_k_rate(). Initial number of bacterias in population No is 1.
So the loop should look like: Because No is equal to 1 we can omit it -> N = e ^ ((1-k) * t) And loop is iterated while N > 0 becase N == 0 means the population is dead. The total time of population`s life equals to t * 20 (minutes). Edit: Updated the code to create the t outside the loop because not all compilers let to use the variable created in the for() outside the loop.
Function total() returns not the maximum of population but the number of the generation with maximum population. You can print the maxN and maxT and t inside the total() (after the loop). Also you can print the value of rate inside calculate_k_rate().
Yes calculate for k is okay but I think theres something wrong with the maxT maxN function. max t is 42 instead of 41 and n is 0.0000