- Oct 10, 2004
- 46
- 0
- 0
One of my projects for class is to write a program to make a number into a palindrome by adding the reverse of a number to it, i.e.
512 +
215
----
727 == palindrome
I am thinking of writing a function to reverse an array, then convert back then add, so something like
int a = 512;
int old[3];
int new[3];
old = inttoarray(a);
for(int loop = 0; loop <length(a); loop++)
{
new[loop] = old[length(a)-loop]
}
return a+arraytoint(new);
the lynchpin is, I have to find a way to convert int to int array and back again, and I have no idea. I've had a look at stringstreams, but I'm trapped in visual C++ 6, and it doesn't seem to work. Any ideas?
512 +
215
----
727 == palindrome
I am thinking of writing a function to reverse an array, then convert back then add, so something like
int a = 512;
int old[3];
int new[3];
old = inttoarray(a);
for(int loop = 0; loop <length(a); loop++)
{
new[loop] = old[length(a)-loop]
}
return a+arraytoint(new);
the lynchpin is, I have to find a way to convert int to int array and back again, and I have no idea. I've had a look at stringstreams, but I'm trapped in visual C++ 6, and it doesn't seem to work. Any ideas?