Link to home
Start Free TrialLog in
Avatar of ReignMan
ReignMan

asked on

Help Writing a Recursive Function

Help, i need to write a recursive function showing that the Sumation of (k-1)/2^k = 0 when k is from 0 to infinity.
hope this makes sense, if not let me know

thanks!
ASKER CERTIFIED SOLUTION
Avatar of burtdav
burtdav

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AngrMgmtDdntWork
AngrMgmtDdntWork

hmm, you sure you got that right? I may be wrong but wouldn't (k-1)/2^k=0 have a single answer? My math skills may not be great, I'm probably wrong. But if what your looking for is x in x = (k-1)/2^k then I believe the following code should work for you. It will print the answers to a file due to the large amount of numbers involved. Running this for 1 minute creates the numbers from 0 to 100000. Heres the code:

#include <stdio.h>
#include <iostream.h>

int a = 0;              
int k = 0;
double c;    
double r = 0;    
double f = 0;    
int g = 0;          
int p = 0;              
int b = 0;              
float ans;              

void main()

{          
     
     FILE * pFile;    

     pFile = fopen ("myfile.txt","w");    

loop1:

     {

     while(b <= f)
                     
         
     {

          if (p = 0)
         
          {
         
               r = 2 * 2;

               p = p++;
         
          }
         
          if (p != 0)

          {

               r = r * 2;

               p = p++;

          }

          b = b++;
         
     }

          c = (k-1);
         
          g = (2^k);

          ans = c/g;
     
         fprintf (pFile, "Variable k being %d resulted in %f\n",k,ans);

          k = k++;

          f = f++;

          r = 0;

          b = 0;

          p = 0;

          goto loop1;

     }

          fclose (pFile);

}




The answers that come out look sorta funny to me, but as I said, Im not a math guy, if it doesnt work, just tell me any I'll try to help you further. Good luck.
whoa, completely ignore my ignorance, i didnt see his much MUCH better answer. Props to burtday