### Thread: C program to print phone words for 7 digit input total question is in comments

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2013
Posts
6
Rep Power
0

#### C program to print phone words for 7 digit input total question is in comments

/*****************************************************************************
Each number on the telephone dial (except 0&1) corresponds to three alphabetic characters. Those correspondences are:
2 ABC
3 DEF
4 GHI
5 JKL
6 MNO
7 PRS
8 TUV
9 WXY
Given a seven digit telephone number, print all 2187 possible "words" that number spells. (They may not be real english words, but just some sequence of characters). Since the digits 0 and 1 have no alphabetic equivalent, an input number which contains those digits should be rejected. The input will be one or more seven digit integers from standard input.The problem can be made a bit more challenging by outputting more than one word per line. Usually about seven words will fit on a line.
****************************************************************************/
2. That looks like fun homework, you should enjoy doing that.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2013
Posts
6
Rep Power
0
Originally Posted by salem
That looks like fun homework, you should enjoy doing that.
thanks for your advice . but here i need small help i think you could help me out i am able to print the combinations of 6 letter word but it should 7 letter words here my code....
Code:
```#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int lev=-1,l=0,n,b[3000][7],val[50],a[50];

void main()
{
int i,j,m,count=0;
char word[8][3]={    {'A','B','C'},
{'D','E','F'},
{'G','H','I'},
{'J','K','L'},
{'M','N','O'},
{'P','R','S'},
{'T','U','V'},
{'W','X','Y'}};
long int phone;

clrscr();
printf("Enter how many numbers?\n");
scanf("%ld",&phone);
n=7;

for(i=0;i<n;i++)
{
val[i]=0;
j=i+1;
a[j]=phone%10;
phone=phone/10;
if(a[j]==0||a[j]==1)
{
printf("invalid input 0&1 are not allowed");
exit(0);
}
}
visit(0);
printf("%d",l);
while(count!=3)
{
for(m=0;m<=l;m++)
{
for(i=0;i<n;i++)
{
switch(b[m][i])
{

case 2:
printf("%c",word[0][count]);
break;
case 3:
printf("%c",word[1][count]);
break;
case 4:
printf("%c",word[2][count]);
break;
case 5:
printf("%c",word[3][count]);
break;
case 6:
printf("%c",word[4][count]);
break;
case 7:
printf("%c",word[5][count]);
break;
case 8:
printf("%c",word[6][count]);
break;
case 9:
printf("%c",word[7][count]);
break;
}
}printf("\t\t\t\t\t");
}
count++;
}

getch();
}
visit(int k)
{
int i;
val[k]=++lev;
if(lev==n)
{
for(i=0;i<n;i++)
{b[l][i]=a[val[i]];
}l++;
}
for(i=0;i<n;i++)
if(val[i]==0)
{
visit(i);
}
lev--;
val[k]=0;
return ;

}```