-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathinteger_in_words.c
70 lines (60 loc) · 1.05 KB
/
integer_in_words.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
64
65
66
67
68
69
70
//TO PRINT INTEGER IN WORDS(CONTAINING NON-ZERO DIGIT)
#include<stdio.h>
#include<math.h>
int reverse(int);
void print(int);
void main()
{
int num,rev;
printf("Enter a number:");
scanf("%d",&num);
rev=reverse(num);//Reverses the number
print(rev);//Print in words
}
int reverse(int n)
{
int i,j,s;
for(i=-1,j=n;j;i++,j/=10){}//Calculates number of digits
for(i,j=n,s=0;j;i--,j/=10)
s+=(j%10)*(pow(10.0,i));
return(s);
}
void print(int x)
{
int a;
while(x)
{
a=x%10;
switch(a)
{
case 1:
printf("One ");
break;
case 2:
printf("Two ");
break;
case 3:
printf("Three ");
break;
case 4:
printf("Four ");
break;
case 5:
printf("Five ");
break;
case 6:
printf("Six ");
break;
case 7:
printf("Seven ");
break;
case 8:
printf("Eight ");
break;
case 9:
printf("Nine ");
break;
}
x/=10;
}
}