-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumToWords.c
47 lines (42 loc) · 1.01 KB
/
NumToWords.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
#include<stdio.h>
int main(){
int num, rev, rem, sum=0;
printf("Number: ");
scanf("%d",&num); //getting input number
while(num>0){
rem = num % 10;
sum = sum * 10 + rem; //Reversing the input number
num = num / 10;
}
num = sum; //setting sum to num
printf("Character: ");
while(num > 0){
rem = num % 10; //Getting last digit
switch(rem){ //checking and printing last digit
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;
case 0: printf("Zero ");
break;
default: printf("Error encountered!!!");
break;
}
num=num/10; //incrementing number
}
return 0;
}