Interview Question
The solution for this problem involves us thinking in terms of Base 26 notation like Hexadecimal (which is 16). I am trying to remember the way we convert Base 16 to Base 10. We could apply the similar logic.
After writing I kind of remember trying to get the modulo of the number any may be first solution leads to that.
void base26(int n)
{
if(n<base) {
putchar('a'+n%26-1);
return;
}
base26(n/26);
putchar('a'+n%26-1);
}
Who is this moron - who comments but does not provide any answers.
1. one issue i can see is negative number check .
void printstring(int num)
- Anonymous May 21, 2010{
if(!num)
return ;
int rem=0;
rem=num%26;
num=num/26;
printstring(num);
printf("%c",96+rem);
}