About recursion void

Hi, i am newbie in c++.
I hope you can help me to write what the meaning and output of this subprogram.
I am really confused.

1
2
3
4
5
6
7
8
9
10
string stc;
void coba(int n,string &st) 
{ int b; 
string sta,stb; 
if (n==0) st = "HEE"; 
else { b = n%2; 
if (n/2>5) stb = 83+b; 
else stb = 65+b; 
coba(n/2, sta); 
st = sta + stb; } }


And my problem is, how to determine the value of stc if calling coba(35,stc).
Please help me guys.... :(
It's all about formatting. Without it the code is unreadable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
using std::string;

string stc;
void coba(int n,string &st) 
{ 
  int b; 
  string sta,stb; 
  
  if (n==0) 
    st = "HEE"; 
  else 
  { 
    b = n%2; 
    if (n/2>5) 
      stb = 83+b; 
    else 
      stb = 65+b; 
      
    coba(n/2, sta); 
    st = sta + stb; 
  } 
}

int main()
{
  coba(35, stc);
  std::cout << stc;
  return 0;
}
HEEBAAATT 
Last edited on
I deeply wanna thank you, Stewbond...
Your answer is awesome, it is helpfull.....


:)))
Topic archived. No new replies allowed.