Convert a sentence into its equivalent mobile numeric keypad sequence in C++

C++Server Side ProgrammingProgramming

In this tutorial, we will be discussing a program to convert a sentence into its equivalent mobile numeric keypad sequence.

For this we will be provided with a string of alphabetical characters. Our task is to print the numeric equivalent of the string i.e the numerical sequence of the keys to type that particular string.


 Live Demo

#include <bits/stdc++.h>
using namespace std;
//computing the numerical sequence
string calc_sequence(string arr[], string input){
   string output = "";
   //length of input string
   int n = input.length();
   for (int i=0; i<n; i++){
      //checking if space is present
      if (input[i] == ' ')
         output = output + "0";
      else {
            int position = input[i]-'A';
            output = output + arr[position];
      return output;
   int main(){
     //storing the sequence in array
      string str[] = {
   string input = "TUTORIALSPOINT";
   cout << calc_sequence(str, input);
   return 0;


Updated on 06-Jan-2020 12:02:35