Given a positive number, convert the number to the corresponding Excel column name.

For example, the following image shows numbers corresponding to Excel columns:

 
Excel column number to name

Practice this problem

 
The main trick in this problem lies in handling the boundary cases, such as the number 26 corresponds to column Z, and the number 27 corresponds to column AA. Similarly, the number 1014 corresponds to column ALZ, and the number 1015 corresponds to column AMA.

Following is the C++, Java, and Python program that handles all these cases beautifully:

C++


Download  Run Code

Java


Download  Run Code

Python


Download  Run Code

Output (will vary):
 
585 — VM
873 — AGO
269 — JI
849 — AFQ
288 — KB
962 — AJZ
549 — UC
572 — UZ
485 — RQ
704 — AAB

 
Also See:

Convert column name in Excel to the corresponding number