-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumtowrd.c
63 lines (63 loc) · 1.47 KB
/
numtowrd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<stdio.h>
#include<conio.h>
int main()
{
int num,mod,n,flag=0;
char *one[]={"one ","two ","three ","four ","five ","six ","seven ","eight ","nine "};
char *ten[]={"ten ","twenty ","thirty ","forty ","fifty ","sixty ","seventy ","eighty ","ninety "};
char *tens[]={"eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "};
printf("input:");
scanf("%d",&num);
if(num>999)
{
printf("out of range 0-999");
}
mod=num/100;
printf("\noutput:");
if(mod)
{
mod--;
printf("%s hundred",one[mod]);
n=num%100;
if(n!=0)
{
printf(" and ");
}
else
{
flag=1;
}
}
else
{
n=num;
}
mod=n/10;
if(mod)
{
n=n%10;
if((mod==1)&&(n==0))
{
printf("%s",ten[0]);
flag=1;
}
else if((mod==1)&&(n>0))
{
n--;
printf("%s",tens[n]);
flag=1;
}
else if(mod>1)
{
mod--;
printf("%s",ten[mod]);
}
}
if(flag==0)
{
n--;
printf("%s",one[n]);
}
getch();
return 0;
}