Find Excel column name from a given column number | C ++ program to find Excel column name from a given column number ; Function to print Excel column name for a given column number ; To store current index in str which is result ; Find remainder ; If remainder is 0 , then a ' Z ' must be there in output ; If remainder is non - zero ; Reverse the string and print result ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE #define MAX  50 NEW_LINE using namespace std ; void printString ( int n ) { char str [ MAX ] ; int i = 0 ; while ( n > 0 ) { int rem = n % 26 ; if ( rem == 0 ) { str [ i ++ ] = ' Z ' ; n = ( n / 26 ) - 1 ; } else { str [ i ++ ] = ( rem - 1 ) + ' A ' ; n = n / 26 ; } } str [ i ] = ' \0' ; reverse ( str , str + strlen ( str ) ) ; cout << str << endl ; return ; } int main ( ) { printString ( 26 ) ; printString ( 51 ) ; printString ( 52 ) ; printString ( 80 ) ; printString ( 676 ) ; printString ( 702 ) ; printString ( 705 ) ; return 0 ; }