C Program to Convert a Given Number to Word

This program first takes a number from the user. Then, it uses a loop to convert the number to words. The loop iterates over the number, and for each digit, it prints the corresponding word from the words array. Finally, the program prints a newline character.

Program :

#include<stdio.h>
#include<conio.h>
int main()
{
int n,sum=0,r;

printf(“Enter the number = “);
scanf(“%ld”,&n);
while(n>0)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
n=sum;
while(n>0)
{
r=n%10;
switch(r)
{
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(“tttt”);
break;
}
n=n/10;
}
return 0;
}

Output :

Leave a Comment

Your email address will not be published.

Shopping Basket
Verified by MonsterInsights