- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Excel Sheet Column Title in C++
Suppose we have a positive integer; we have to find its corresponding column title as appear in an Excel sheet. So [1 : A], [2 : B], [26 : Z], [27 : AA], [28 : AB] etc.
So, if the input is like 28, then the output will be AB.
To solve this, we will follow these steps −
while n is non-zero, do −
n := n - 1
res := res + n mod 26 + ASCII of 'A'
n := n / 26
reverse the array res
return res
Example
Let us see the following implementation to get a better understanding −
#include <bits/stdc++.h> using namespace std; class Solution { public: string convertToTitle(int n) { string res; while(n){ res += (--n)%26 + 'A'; n /= 26; } reverse(res.begin(), res.end()); return res; } }; main(){ Solution ob; cout << (ob.convertToTitle(30)); }
Input
30
Output
AD
- Related Articles
- Excel Sheet Column Number in C++
- Find Excel column number from column title in C++
- Python - Plotting column charts in excel sheet using XlsxWriter module
- How to add a chart title in Excel?
- Program to find spreadsheet column title from the column number in C++
- Program to find spreadsheet column number from the column title in C++
- Python - Plotting charts in excel sheet using openpyxl module
- Python - Plotting Area charts in excel sheet using XlsxWriter module
- Python - Plotting bar charts in excel sheet using XlsxWriter module
- Python - Plotting Combined charts in excel sheet using XlsxWriter module
- Python - Plotting Doughnut charts in excel sheet using XlsxWriter module
- Python - Plotting Line charts in excel sheet using XlsxWriter module
- Python - Plotting Pie charts in excel sheet using XlsxWriter module
- Python - Plotting Radar charts in excel sheet using XlsxWriter module
- Python - Plotting scatter charts in excel sheet using XlsxWriter module

Advertisements