The Program in C++ Program to Get Excel Column Number in Excel Column Title is given below:
#include <iostream>
#include <string>
using namespace std;
int getColumnNumber(string columnTitle) {
int columnNumber = 0;
for (int i = 0; i < columnTitle.length(); i++) {
columnNumber = columnNumber * 26 + (columnTitle[i] - 'A' + 1);
}
return columnNumber;
}
int main() {
string columnTitle;
cout << "Hello Codeauri Family,enter the Excel column title here to find out the Excel Column Number: ";
cin >> columnTitle;
cout << "Okay,the Column number is : " << getColumnNumber(columnTitle) << endl;
return 0;
}
Output:
Hello Codeauri Family,enter the Excel column title here to find out the Excel Column Number: KP
Okay,the Column number is : 302
Pro-Tips💡
In this program, the getColumnNumber
function converts the given Excel column title to its corresponding column number by iterating through each character in the title
and using the ASCII value of the character to calculate the column number.
The main
function takes the user input for the Excel column title and outputs the corresponding column number by calling the getColumnNumber
function.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.