Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. using namespace std;
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <cmath>
  7.  
  8. const int N = 20, D = 46;
  9.  
  10.  
  11. int method1(int k) {
  12. int a = 0, b = 1;
  13. for (int i = 0; i < k; ++i) {
  14. b = a + b;
  15. a = b - a;
  16. }
  17. return a;
  18. }
  19.  
  20. int main()
  21. {
  22. clock_t start;
  23. double duration;
  24. int RandFib[N];
  25. int Fib1[N], Fib2[N], Fib3_2[N], Fib4[N];
  26. float Fib3_1[N];
  27.  
  28. srand(time(NULL));
  29.  
  30. for (int i = 0; i < N; ++i) {
  31. if (i % 5 == 0) cout << endl;
  32. RandFib[i] = rand() % (D + 1);
  33. cout << RandFib[i] << "\t";
  34. }
  35.  
  36. cout << endl;
  37. cout << endl;
  38.  
  39. start = clock();
  40. for (int i = 0; i < N; ++i) {
  41. Fib1[i] = method1(RandFib[i]);
  42. }
  43. duration = (clock() - start) / (double)CLOCKS_PER_SEC;
  44. cout << "Duration: " << duration << endl << endl;
  45.  
  46. for (int i = 0; i < N; ++i) {
  47. cout << Fib1[i] << endl;
  48. }
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement