fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define n 250000
  5.  
  6. int main(){
  7. int age[n] = {13,13,13,13,13,13};
  8. int sex[n] = {1, 1, 1, 2, 2, 2}; //0=nonexistent, 1=female, 2=male
  9. int population = 6;
  10. int t;
  11. int i;
  12.  
  13. for(t=0; t<107; t++){
  14. int newsex = 0;
  15. for(i=0; i<n; i++){
  16. if (sex[i] == 0) break;
  17.  
  18.  
  19. if( (age[i]%2==0) && (age[i]>=13) && (age[i]<=33) && (sex[i]==1) ){
  20. sex[population] = 0.5*(1-pow(-1,newsex))+1;
  21. newsex++;
  22. population++;
  23. }
  24.  
  25. age[i]++;
  26. }
  27. }
  28.  
  29. int overThirteen = 0;
  30. int fertileFemales = 0;
  31.  
  32. for(i=0; i<n; i++){
  33. if ( sex[i] == 0 ) break;
  34. if ( age[i] > 13 ) overThirteen++;
  35. if ( (age[i]>=13) && (age[i]<=33) && (sex[i]==1) )fertileFemales++;
  36. }
  37.  
  38. printf("total population: %d\n", population);
  39. printf("percentage of population over 13: %g%%\n", (double)overThirteen/population*100);
  40. printf("total fertile female population: %d\n", fertileFemales);
  41. }
Success #stdin #stdout 0s 3992KB
stdin
Standard input is empty
stdout
total population: 35017
percentage of population over 13: 41.18%
total fertile female population: 5578