Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. > #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6.  
  7.  
  8. int k = 20; // number of years to calculate for
  9. int pn = 10; // the population of animals for the first year
  10. double g = 275; // rate of growth
  11. g = g/100.00;
  12. double h = 20; // rate of animal death/animals leaving population
  13. h = h/100.00;
  14. int M = 100; // carrying capacity of the ecosystem
  15.  
  16.  
  17.  
  18. /*
  19. Implementing Verhulst's Formula in C++
  20. */
  21.  
  22.  
  23.  
  24. int i;
  25. int pop;
  26. for (i = 1; i <= k ; i++)
  27. {
  28. pop = (((1 + (g - h)) * pn) - g*(pn*pn)/M) + .5; // the equation
  29. pn = pop; // this takes the new value of pop and inserts it as pn, to be looped until i <= k
  30. cout << i << " " << pop << endl;
  31. }
  32.  
  33.  
  34. return 0;
  35.  
  36. }
  37.  
  38. 1 35
  39. 2 96
  40. 3 88
  41. 4 102
  42. 5 75
  43. 6 116
  44. 7 37
  45. 8 100
  46. 9 80
  47. 10 112
  48.  
  49. 1 25
  50. 2 70
  51. 3 120
  52. 4 33
  53. 5 94
  54. 6 90
  55. 7 98
  56. 8 86
  57. 9 92
  58. 10 70
  59.  
  60. int i;
  61. int pop;
  62. for (i = 1; i <= k ; i++)
  63. {
  64. pop = (((1 + (g - h)) * pn) - g*(pn*pn)/M) + .5; // the equation
  65. pn = pop; // this takes the new value of pop and inserts it as pn, to be looped until i <= k
  66. cout << i << " " << pop << endl;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement