Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #define PI 3.14159265
  5.  
  6. void beetleSimulation(int size, int iterations);
  7.  
  8. int main ( int argc, char *argv[] )
  9. {
  10. if ( argc != 3 )
  11. {
  12. printf("Program only has %d arguments!\n", argc);
  13. return 0;
  14. }
  15. else
  16. {
  17. beetleSimulation(atoi(argv[1]), atoi(argv[2]) );
  18. }
  19. return 0;
  20. }
  21.  
  22. void beetleSimulation(int size, int iterations){
  23. int i;
  24. int xCount = 0;
  25. int yCount = 0;
  26. int timeCount = 0;
  27. int overallCount = 0;
  28. double averageTime;
  29. int degree;
  30. double radian;
  31.  
  32. for(i=0; i < 10000; i++){
  33. while(xCount < 20 || xCount > -20 || yCount <20 || yCount >-20){
  34. timeCount += 1;
  35. degree = rand() % 360;
  36. radian = degree / 180 * PI;
  37. xCount += sin(radian);
  38. yCount += cos(radian);
  39. }
  40. overallCount += timeCount;
  41. }
  42.  
  43. averageTime = overallCount/iterations;
  44. printf("Average Time is: %f\n", averageTime);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement