Advertisement
cardel

Ejemplo2 MDII 14 DIC

Dec 14th, 2020
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double recursivo(int n){
  6.   if(n==0){
  7.     return 4.0;
  8.   }
  9.   else{
  10.     if(n==1){
  11.       return 8.0;
  12.     }
  13.     else{
  14.       return 7*recursivo(n-1)-3*recursivo(n-2);
  15.     }
  16.  
  17.   }
  18.  
  19. }
  20.  
  21.  
  22. double formula(int n){
  23.   double A = (2.0-6.0/sqrt(37));
  24.   double B = (2.0+6.0/sqrt(37));
  25.   double r1 = pow((7.0+sqrt(37))/2,n);
  26.   double r2 = pow((7.0-sqrt(37))/2,n);
  27.  
  28.   return A*r1+B*r2;
  29. }
  30.  
  31. int main() {
  32.     for(int i = 0; i<20; i++){
  33.  
  34.       cout <<" n "<< i <<"recursiva: " << recursivo(i) << " formula "<< formula(i) << endl;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement