Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<time.h>
  3.  
  4. int Hanoi(int n){
  5. if(n == 1)
  6. return 1;
  7. else
  8. return 2 * Hanoi(n-1) + 1;
  9. }
  10.  
  11.  
  12.  
  13. int main(int argc, char ** argv)
  14. {
  15. int i;
  16. int m[10];
  17. double t[10];
  18. FILE * f;
  19. f = fopen("Fichero6a.txt", "w+");
  20. for (i = 0; i < 10; i++)
  21. {
  22. clock_t start = clock();
  23. Hanoi(i+1);
  24. t[i] = ((double)(clock() - start)/CLOCKS_PER_SEC);
  25. m[i] = Hanoi(i+1);
  26. }
  27. for(i = 0; i < 10; i++)
  28. {
  29. fprintf(f,"%d %f %d\n",i+1, t[i], m[i]);
  30. }
  31.  
  32. fclose(f);
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement