```
/*****************************************
* Written by Mathias Van Malderen
* Copyright (c) 2009 Mathias Van Malderen
******************************************/
/***************************
itos(int a)
****************************/
string itos(int a)
{
/* Convert an integer to a string */
int b = 0, c = 1, n = 0;
string result;
while(apow(10,n) < a) n++;
if(n != 0) n--;
b = apow(10,n);
while((b*c) < a) c++;
if(n != 0) c--;
a -= (b*c);
result += digit2str(c);
if(n != 0) result += itos(a);
return result;
}
/***************************
DEPENDENCIES
****************************/
int apow(const int &x, int y)
{
/* Raise x to the power of y */
int result = 1;
if(y < 0)
return apow(1/x, -y);
for(int i = y; i > 0; i--)
result *= x;
return result;
}
string digit2str(short digit)
{
/* Convert a digit to a string */
string tmp;
if(digit >= 0 && digit <= 9)
{
tmp = digit + '0';
return tmp;
}
return "";
}
```

**Are you able to help answer this sponsored question?**

Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.

Recommended Topics