Coders Packet

Print all possible words from phone keypad using c++

By Ravi Kumar Mehta

We have to print all possible words that can be formed by pressing those digits of the mobile keyboard using c++.

Approach: In this code, i denotes the index of input and j denotes the index of output. 

      In base case: if the input array reaches the last position of the input string that means

                           your work is done. now you will terminate and print that output.

      recursive case: you extract the first digit and iterate the string of the keypad array. 

                             now we call recursively to fill the remaining part of the words.

Input format: a numeric string.

Output format: all possible words made by that numeric string.

explanation: 

                 1

            2
          ABC

             3
            DEF

                 4
               GHI

             5
           JKL

              6
            MNO

                  7
             PQRS

            8
          TUV

              9
           WXYZ

                *

           0

              #

 ex-   input: 666 

output:

MMM
MMN
MMO
MNM
MNN
MNO
MOM
MON
MOO
NMM
NMN
NMO
NNM
NNN
NNO
NOM
NON
NOO
OMM
OMN
OMO
ONM
ONN
ONO
OOM
OON
OOO

Download Complete Code

Comments

No comments yet