944,193 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3379
  • C++ RSS
Nov 29th, 2004
0

Really Weird Error... Fibonacci Nums

Expand Post »
I'm having some real problems with a code that is supposed to find Fibonacci numbers using recursive, iterative, and optimized recursive techniques. I keep on getting this really strange error though: "fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786) Please choose the technical Support command on the Visual C++ Help menu, or open the technical Support help file for more information Error executing cl.exe.". If anyone could think of some advice, it would be really helpful. Thanks!

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. typedef int* IntPtr;
  7.  
  8. long iter(int n)
  9. {
  10. int a = 1, b = 1;
  11. for (int i = 2; i <= n; i++)
  12. {
  13. int c = a + b;
  14. a = b;
  15. b = c;
  16. }
  17. return b;
  18. }
  19.  
  20. int optRecur(int n, int array[])
  21. {
  22. if (array[n] != 0)
  23. return array[n];
  24. if ((n == 0) || (n == 1))
  25. array[n] = 1;
  26. else
  27. array[n] = optRecur(n-1,array) + optRecur(n-2,array);
  28. return array[n];
  29. }
  30.  
  31. void optRecurHelp(int n)
  32. {
  33. int* a = NULL;
  34. a = new int[n];
  35. for(int i = 0; i <= n; ++i)
  36. a[i] = 0;
  37. optRecur(n,a);
  38. delete [] a;
  39. a = NULL;
  40. }
  41.  
  42. long recur(int n)
  43. {
  44. if ( n == 0 || n == 1 )
  45. return 1;
  46. else
  47. return recur(n - 1) + recur(n - 2);
  48. }
  49.  
  50. long time(int n, int funct)
  51. {
  52. double emptyLoop;
  53. double j;
  54.  
  55. if(funct == 1)
  56. {
  57. clock_t start,end;
  58. start = clock();
  59. for (int i=0;i<100000000;i++)
  60. recur(n);
  61. end = clock();
  62. emptyLoop = end-start;
  63. double time_passed = static_cast<double>(end-start)/CLOCKS_PER_SEC;
  64. j = (((end-start)-emptyLoop)/100000000);
  65. }
  66. if(funct == 2)
  67. {
  68. clock_t start,end;
  69. start = clock();
  70. for (int i=0;i<100000000;i++)
  71. iter(n);
  72. end = clock();
  73. emptyLoop = end-start;
  74. double time_passed = static_cast<double>(end-start)/CLOCKS_PER_SEC;
  75. j = (((end-start)-emptyLoop)/100000000);
  76. }
  77. if(funct == 3)
  78. {
  79. clock_t start,end;
  80. start = clock();
  81. for (int i=0;i<100000000;i++)
  82. optRecurHelp(n);
  83. end = clock();
  84. emptyLoop = end-start;
  85. double time_passed = static_cast<double>(end-start)/CLOCKS_PER_SEC;
  86. j = (((end-start)-emptyLoop)/100000000);
  87. }
  88. return j;
  89. }
  90.  
  91. int main()
  92. {
  93. int num1;
  94. int num2;
  95.  
  96. cout << "What number would you like to compute? " << endl;
  97. cin >> num1;
  98. cout << "What function (recursive=1, iterative=2, optimized recursive=3)? " << endl;
  99. cin >> num2;
  100. cout << time(num1,num2) << endl;
  101. return 0;
  102. }
Last edited by alc6379; Nov 29th, 2004 at 3:02 pm. Reason: added [code] tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lostinthespiral is offline Offline
5 posts
since Oct 2004
Nov 29th, 2004
0

Re: Really Weird Error... Fibonacci Nums

Try removing optimazation options 0g/ 0i/ 0a. Remove one at a time to see wich one might be the culprit.
Reputation Points: 14
Solved Threads: 0
Newbie Poster
big146 is offline Offline
18 posts
since Jul 2004
Nov 29th, 2004
0

Re: Really Weird Error... Fibonacci Nums

Tried. Fixed. Still get the same error.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lostinthespiral is offline Offline
5 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: help with inputing a string in c
Next Thread in C++ Forum Timeline: Size





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC