Facebook
From asd, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 125
  1. #include <iostream>
  2. #include <chrono>
  3. using namespace std;
  4. int fibr(int n){
  5.  if (n<=1)
  6.   return n;
  7.  return fibr(n-1)+fibr(n-2);
  8. }
  9. int fibi(int n){
  10.  int a=0,b=1,c,i;
  11.  if (n==0){
  12.   return a;
  13.  }
  14.  for (i=2;i<=n;i++){
  15.   c=a+b;
  16.   a=b;
  17.   b=c;
  18.  }
  19.  return b;
  20. }
  21. int main(){
  22.  int n=50,i;
  23.  for(i=1;i<=n;i++){
  24.   auto startR=chrono::high_resolution_clock::now();
  25.   cout << "Bazgashti:\n";
  26.   cout << "fib(" << i << ")=" << fibr(i) << " ";
  27.   auto stopR=chrono::high_resolution_clock::now();
  28.    auto durati>(stopR-startR);
  29.   cout << "Time:" << durationR << "\n";
  30.   auto startI=chrono::high_resolution_clock::now();
  31.   cout << "Tekrari:\n"
  32.   cout << "fib(" << i << ")=" << fibi(i) << " ";
  33.   auto stopI=chrono::high_resolution_clock::now();
  34.    auto durati>(stopI-startI);
  35.   cout << "Time:" << durationI << "\n";
  36.  }
  37.  return 0;
  38. }
  39.