Write the program to print all possible words from keypad 2 and 3 from keypad mobile.


 /*

click on below the  link and  run this program.

   http://cpp.sh/8g5dbz*/

Some points : 

1) if we want  to add characters make a string than
we should  make a string variable f=""; and add in intial with characters
example " let suppose we want add char a[0]+char b[0] and to make a string
if we add simply then we get 197
but if we add f+a[0]+b[0] then we will get string ( ad).


2)to change  ASCII code of string or character into Integer then simply      suppose char a ="A";

to_string(a)//output 65(ASCII code of A)  in string form.

      */


#include<iostream>
#include<string>
using namespace std;

string keypadarr[]={" ","/","abc","def","ghi","jkl","mno","pqr","so on"};

void keypadword(string a,string b ) //user define function
{    
    if(a.size()==0)
       { return;}              //base condition
   
     char ch =a[0];
     keypadword(a.substr(1),b);//again call function (recursion)

   for(int i=0; i<b.size();i++)
      {   string k="";
       cout<<(k+ch+b[i])<<endl;
      }
}

int main()
{ string a="23";

  string m = keypadarr[a[0]-'0'];//String change into integer  when subtract by '0'
  string n =keypadarr[a[1]-'0'];
   
  keypadword(m,n);//function call

    return 0;
}



Comments

Popular posts from this blog

Use of Recursion