Advertisement
agusbd

rekursif #2

Mar 10th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. float der(int,int);
  7. int derx(int,int);
  8.  
  9. main(){
  10.    
  11.     cout<<der(5,1)<<endl;
  12.     cout<<derx(5,1);
  13.    
  14. }
  15.  
  16.  
  17. float der(int n,int c){
  18.     char k;
  19.     if(!n){
  20.        
  21.         return 0;
  22.     }
  23.     int x;
  24.     if(n%4==0){
  25.         x=1;
  26.     }else{
  27.         x= -1;
  28.     }
  29.  
  30.         if(c%4==0){
  31.            
  32.             k='+';
  33.         }
  34.         else{
  35.             k='-';
  36.         }
  37.     cout<<k<<1<<"/"<<(2*(c));
  38.     if(n==1)
  39.     cout<<endl<<"S: ";
  40.     return 1/(2.0*n*x)+der(n-1,c+1);
  41.    
  42.    
  43. }
  44.  
  45. int derx(int n,int c){
  46.    
  47.     int x;
  48.     char y;
  49.     if(!n){
  50.      cout<<endl<<"S =";
  51.     return 0;
  52.    
  53. }
  54.    
  55.     if(n%2==0){
  56.         x=-1;
  57.     }else{
  58.         x= 1;
  59.     }
  60.     y= x==1 ? '\0': c%1==0 ? '+' : '-';
  61.     cout<<x*(1+(c-1)*2)<<y;
  62.     return x*(1+(n-1)*2)+derx(n-1,c+1);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement