C program that will input a number in digit (up to millions) and output its word equivalent.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

hi beloved coders all over the world i just want to have an extra help from you in creating a C program that will input a number in digit (up to millions) and output its word equivalent. Here's what i've got so far.  The code below will output 
its equivalent words  from 0 to 100 but i need 101,102,etc  up to millions to be outputted also. Can you help me continue with the code and if the code below has mistakes can you correct it. Thank you and regards.

#include<stdio.h>
#include<string.h>
main ()
{
    char a[20];
    char *single[] = {"Zero","One","two","three","four","five","six","seven","eight","nine"};
    char *double_digit[] = {"","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
    char *tens_place[] = {"","","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
    char *hundred_place[] = {"","","","One hundred","two hundred","three hundred","four hundred","five hundred","six hundred","seven hundred","eight hundred","nine hundred"};
    printf("Enter a number\n");
    scanf("%s",a);
    
    int len = strlen(a);
    int num;
    if(len == 1)
    { num = a[0] - 48;
        printf("%s ",single[num]);
    }
    if(len ==2 && a[0] == 49)
    { num = (a[0] - 48) + (a[1]-48);
        printf("%s ",double_digit[num]);
    }
    else if(len == 2 && a[1] == 48)
    {
      num = (a[0] - 48) + (a[1]-48);
      printf("%s ",tens_place[num]);
    }
    else if(len == 2)
    {
      num = a[0] - 48;
      printf("%s ",tens_place[num]);
      num = a[1] - 48;
      printf("%s ",single[num]);
    }
    else if(len == 3 && a[1] == 48)
    {
      num = (a[1] - 47 ) + (a[0]-47);
        printf("%s ",hundred_place[num]);
    }
    else if(len == 3)
    {
      num = a[0] - 47;
      printf("%s ",hundred_place[num]);
      num = a[0] - 50 ;
      printf("%s ",single[num]);
    }
    }

3G
4G+
1.70
9:52
PH)
KB/s 10%
pogi.c
1 #include<stdio.h>
2 #include<string.h>
3 main ()
4 {
char a[20];
char *single[] = {"Zero","One","two","three",
four","five","six","seven","eight","nine"};
char *double_digit[] = {"","ten","eleven","
twelve","thirteen","fourteen","fifteen","
sixteen","seventeen","eighteen","nineteen"};
char *tens_place[] = {"","","twenty","thirty","
fourty","fifty","sixty","seventy","eighty","
ninety"};
char *hundred_place[] = {"","","","One hundred",
"two hundred","three hundred","four hundred",'
five hundred","six hundred","seven hundred",'
eight hundred","nine hundred"};
printf("Enter a number\n");
scanf("%s",a);
5
7
8
9
10
11
12
13
int len = strlen(a);
%3D
14
int num;
if(len == 1)
{ num = a[0] - 48;
printf("%s ",single[num]);
}
if(len ==2 && a[0] == 49)
{ num = (a[0] - 48) + (a[1]-48);
printf("%s ",double_digit[num]);
}
else if(len == 2 && a[1]
{
15
16
%3D
17
70S
18
19
20
21
22
23
48)
24
25
num =
(a[0] - 48) + (a[1]-48);
printf("%s ",tens_place[num]);
}
else if(len
{
26
27
28
2)
29
a[0] - 48;
printf("%s ",tens_place[num]);
a[1] - 48;
printf("%s ",single[num]);
}
else if(len == 3 && a[1] ==
30
num =
31
32
num
33
34
35
48)
Q
Run
Transcribed Image Text:3G 4G+ 1.70 9:52 PH) KB/s 10% pogi.c 1 #include<stdio.h> 2 #include<string.h> 3 main () 4 { char a[20]; char *single[] = {"Zero","One","two","three", four","five","six","seven","eight","nine"}; char *double_digit[] = {"","ten","eleven"," twelve","thirteen","fourteen","fifteen"," sixteen","seventeen","eighteen","nineteen"}; char *tens_place[] = {"","","twenty","thirty"," fourty","fifty","sixty","seventy","eighty"," ninety"}; char *hundred_place[] = {"","","","One hundred", "two hundred","three hundred","four hundred",' five hundred","six hundred","seven hundred",' eight hundred","nine hundred"}; printf("Enter a number\n"); scanf("%s",a); 5 7 8 9 10 11 12 13 int len = strlen(a); %3D 14 int num; if(len == 1) { num = a[0] - 48; printf("%s ",single[num]); } if(len ==2 && a[0] == 49) { num = (a[0] - 48) + (a[1]-48); printf("%s ",double_digit[num]); } else if(len == 2 && a[1] { 15 16 %3D 17 70S 18 19 20 21 22 23 48) 24 25 num = (a[0] - 48) + (a[1]-48); printf("%s ",tens_place[num]); } else if(len { 26 27 28 2) 29 a[0] - 48; printf("%s ",tens_place[num]); a[1] - 48; printf("%s ",single[num]); } else if(len == 3 && a[1] == 30 num = 31 32 num 33 34 35 48) Q Run
3.00 10%
KB/s
3G
4G+
9:52
PH)
pogi.c
34
else if(len == 3 && a[1]
{
num = (a[1] - 47 ) + (a[0]-47);
printf("%s "
}
else if(len == 3)
{
num = a[0]
35
48)
36
37
38
,hundred_place[num]);
39
40
41
= a[0] - 47;
printf("%s ",hundred_place[num]);
num = a[0]
printf("%s ",single[num]);
}
}
42
43
44
- 50 ;
%3D
45
46
47
48
Run
Transcribed Image Text:3.00 10% KB/s 3G 4G+ 9:52 PH) pogi.c 34 else if(len == 3 && a[1] { num = (a[1] - 47 ) + (a[0]-47); printf("%s " } else if(len == 3) { num = a[0] 35 48) 36 37 38 ,hundred_place[num]); 39 40 41 = a[0] - 47; printf("%s ",hundred_place[num]); num = a[0] printf("%s ",single[num]); } } 42 43 44 - 50 ; %3D 45 46 47 48 Run
Expert Solution
steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education