Last semester I took a logic and program design class and had to make a recursive program that turned a decimal number into it's binary equivalent using recursion. This gave me the idea a couple days ago to come up with one in TI-BASIC (don't ask me why, just seemed fun). However, true recursion (or at least the way I was doing it in C++) isn't really possible in TI-BASIC so I had to come up with a way of simulating it, which is what I did. This has no real use or anything, I just thought it was a neat little thing that someone might want to see. Also, in no way is it probably optimized as much as it could be.
C→dim(L1
2fPart(A/2→L1(C
iPart(A/2→A
If A>0
Then
C+1→C
prgmC
End
If C>0
Disp L1(C
C-1→C
Output(1,1,"
To use this you need to set
C to one and
A to the decimal number you want to convert before you run the program.
Edit:
Here is the code I'm basically trying to simulate.
Note: I know it may not be the best written but I'm still new to C++ and it works so I'm happy.
#include <iostream>
using namespace std;
void convert(int num)
{
if(num>0)
{
convert(num/2);
}
else {;}
cout<<num%2;
return;
}
int main()
{
int num;
cout<<"Enter a number: ";
cin>>num;
convert(num);
cout<<endl;
system("pause");
return 0;
}