
- 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 number from the column title in C++
Suppose we have a column title of spreadsheet. We know that the spreadsheet column numbers are alphabetic. It starts from A, and after Z, it will AA, AB, to ZZ, then again AAA, AAB, to ZZZ and so on. So column 1 is A, column 27 is Z. Here we will see how to get the column letter if number of column is given. So if the column number is 80, then it will be CB. So we have to find the corresponding column title from the number. If the input is like 30, it will AD.
Example
#include<iostream> #include<algorithm> using namespace std; void showColumnLetters(int n) { string str = ""; while (n) { int rem = n%26; if (rem==0) { str += 'Z'; n = (n/26)−1; } else{ str += (rem-1) + 'A'; n = n/26; } } reverse(str.begin(), str.begin() + str.length()); cout << str << endl; } int main() { int n = 700; cout << "Cell name of " << n << " is: "; showColumnLetters(700); }
Input
700
Output
Cell name of 700 is: ZX
- Related Articles
- Program to find spreadsheet column title from the column number 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?
- Program to perform excel spreadsheet operation in Python?
- How to find the number of levels in R for a factor column?
- 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