
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Program to find spreadsheet column title from the column number in C++
Suppose we have a positive integer value; we have to find its corresponding column title as appear in a spread sheet. So [1 : A], [2 : B], [26 : Z], [27 : AA], [28 : AB] etc.
So, if the input is like 29, then the output will be AC.
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
Let us see the following implementation to get better understanding −
Example
#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
- Program to find spreadsheet column number from the column title in C++
- Find Excel column number from column title in C++
- Excel Sheet Column Title in C++
- How to find the highest number in a column?
- C program to print Excel column titles based on given column number
- Program to find number of elements in matrix follows row column criteria in Python
- How to get column index from column name in Python Pandas?
- How to find the column number of a string column based on a string match in an R data frame?
- How to find the number of levels in R for a factor column?
- Program to perform excel spreadsheet operation in Python?
- How to subtract column values from column means in R data frame?
- Find square of the following number using column method: $24$.
- Find integer within +/- 1 from a column in MySQL
- Find maximum value from a VARCHAR column in MySQL
- Subtracting a number from a single MySQL column value?

Advertisements