Help C Programming

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]);
	}
	}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thank you so much for the edit :slight_smile:

Do you see any patterns between the following numbers:

123 - “one hundred twenty three”
123,123 - “one hundred twenty three thousand, one hundred twenty three”
123,123,123 - “one hundred twenty three million, one hundred twenty three thousand, one hundred twenty three”

The groups of three are pronounced exactly the same with an extra word thrown in at the end for thousand and million. Does that give you a little more insight into how you might solve this?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.