Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Programming Question Write a program that translates an alphabetic phone numbe

ID: 3808872 • Letter: C

Question

C Programming Question

Write a program that translates an alphabetic phone number into numeric form: Enter phone number: CALLATT 2255288 In case you don't have a telephone nearby, here are the letters on the keys: 2=ABC, 3=DEF, 4-GHT, 5-JKL, 6-MNO. 7=PRS. 8 TUV. 9=WXY. If the original phone number contains nonalphabetic characters (digits or punctuation for example) leave them unchanged: Enter phone number: 1-800-COL-LECT 1-800-265-5328 You may assume that any letters entered by the user are upper case.

Explanation / Answer

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main ()
{
   //Declaring variables
char charphoneNum[100];
char phNum[100];
  
printf("Enter the phone number :");
scanf("%s",&charphoneNum);

int i,j=0;
for(i=0;i<strlen(charphoneNum);i++)
{
    if(charphoneNum[i]=='A' || charphoneNum[i]=='B'||charphoneNum[i]=='C')
    {
        phNum[j]='2';
        j++;
       }
    else if(charphoneNum[i]=='D' || charphoneNum[i]=='E'||charphoneNum[i]=='F')
    {
        phNum[j]='3';
        j++;
       }
    else if(charphoneNum[i]=='G' || charphoneNum[i]=='H'||charphoneNum[i]=='I')
    {
        phNum[j]='4';
        j++;
       }
    else if(charphoneNum[i]=='J' || charphoneNum[i]=='K'||charphoneNum[i]=='L')
    {
        phNum[j]='5';
        j++;
       }
    else if(charphoneNum[i]=='M' || charphoneNum[i]=='N'||charphoneNum[i]=='O')
    {
    phNum[j]='6';
       j++;
       }
    else if(charphoneNum[i]=='P' || charphoneNum[i]=='R'||charphoneNum[i]=='S')
    {
    phNum[j]='7';
          j++;
       }
    else if(charphoneNum[i]=='T' || charphoneNum[i]=='U'||charphoneNum[i]=='v')
    {
    phNum[j]='8';
    j++;
         
       }
    else if(charphoneNum[i]=='W' || charphoneNum[i]=='X'||charphoneNum[i]=='Y')
    {
    phNum[j]='9';
    j++;
         
       }
    else if(isdigit(charphoneNum[i]))
    {
    phNum[j]=charphoneNum[i]-'0';
           j++;
       }
       else if(charphoneNum[i]='-')
       {
          phNum[j]=charphoneNum[i];
           j++;
       }
  

   
   }

for(i=0;i<j;i++)
{
    printf("%c",phNum[i]);
   }
  
return 0;
}