MS Excel columns has a pattern like A, B, C, … ,Z, AA, AB, AC,…. ,AZ, BA, BB, … ZZ, AAA, AAB ….. etc. In other words, column 1 is named as “A”, column 2 as “B”, column 27 as “AA”.
Read full article from Find Excel column name from a given column number | GeeksforGeeks
void
printString(
int
n)
{
char
str[MAX];
// To store result (Excel column name)
int
i = 0;
// To store current index in str which is result
while
(n>0)
{
// Find remainder
int
rem = n%26;
// If remainder is 0, then a 'Z' must be there in output
if
(rem==0)
{
str[i++] =
'Z'
;
n = (n/26)-1;
}
else
// If remainder is non-zero
{
str[i++] = (rem-1) +
'A'
;
n = n/26;
}
}
str[i] =
'\0'
;
// Reverse the string and print result
cout << strrev(str) << endl;
return
;
}