🔒 Closed Mga master Pa help

Status
Not open for further replies.

Pulstarejdei

Established
mga master pakitingin sa code anong kulang or mali.
ito kasi ang gagawain , Write a C program that inputs a number up to (millions) and output its equivalent word/words.
Example:
1
one

2675
two thousand six hundred seventy five

Eto yung code na mag o.output lang
up to 100 lang pero pag 101 ayaw na po. then ok pa siya mag o.output pa ng 200, 300,400, 500,600,700 up to 900 pero pag 201,202 ayaw na po.

#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]);
}
}
 
#include <stdio.h>
#include <string.h>

int main()
{
char a[20];

char number_str[10];
int length;
char *single[10] = {"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
char *double_digit[10] = {"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
char *tens_place[10] = {"Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
char *tens_power[] = {"hundred", "thousand"};
printf("Enter a number:\n");
scanf("%s",a);
char c = getchar();

if(c == '\n')
{
length = strlen(a);

if(length == 1)
{
printf("%s",single[a[0] - 48]);
}
if(length == 2)
{
if(a[0]== 49)
{
printf("%s",double_digit[a[1]- 48]);
}
else
{
if(a[1]== 48)
{
printf("%s",tens_place[a[0]-50]);
}
else
{
printf("%s%s%s",tens_place[a[0]-50]," ", single[a[1]-48]);
}
}
}
if(length == 3)
{
if(a[1] ==48 && a[2]==48)
{
printf("%s%s",single[a[0]-48], " hundred");
}
else if(a[1]==48)
{
printf("%s%s%s", single[a[0]-48]," hundred ",single[a[2]-48]);
}
else if(a[1]==49)
{
printf("%s%s%s", single[a[0]-48], " hundred ", double_digit[a[2]-48]);
}
else
{
if(a[2]==48)
{
printf("%s%s%s", single[a[0]-48], " hundred ",tens_place[a[1]-50]);
}
else
{
printf("%s%s%s%s%s", single[a[0]-48], " hundred ",tens_place[a[1]-50], " ", single[a[2]-48]);
}
}
}
if(length ==4)
{
if(a[1]== 48 && a[2]==48 && a[3]==48)
{
printf("%s%s",single[a[0]-48], " Thousand");
}
else if (a[1]==48 && a[2]== 48)
{
printf("%s%s%s",single[a[0]-48], " Thousand ",single[a[3]-48]);
}
else if( a[1]==48)
{
if(a[2]==49)
{
printf("%s%s%s",single[a[0]-48], " Thousand ",double_digit[a[3]-48]);
}
else
{
if(a[3]==48)
{
printf("%s%s%s",single[a[0]-48], " Thousand ",tens_place[a[2]-50]);
}
else
{
printf("%s%s%s%s%s",single[a[0]-48], " Thousand ",tens_place[a[2]-50]," ", single[a[3]-48]);
}
}
}
else if(a[2] ==48 && a[3]==48)
{
printf("%s%s%s%s",single[a[0]-48], " Thousand ",single[a[1]-48], " hundred");
}
}
}
}

Boss try nyo to kaso hanggang thousand lang sya.
 
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 445
    Views
  • 2
    Participants
Last reply from:
Pulstarejdei

Trending Topics

Online now

Members online
1,089
Guests online
2,292
Total visitors
3,381

Forum statistics

Threads
2,332,512
Posts
29,265,852
Members
1,144,361
Latest member
cambodiaapplestore
Back
Top