Program to accept a number as input and print number in words as output.
(The program has limit from 1 to 9999, which can be edited and increased)
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char num_name['z'];
int num,temp;
cout<<"Enter the number : ";
cin>>num;
strcpy(num_name,"Number Name : ");
if(num>=100)
{
temp=num/1000;
switch(temp)
{
case 1: strcat(num_name," One Thousand");break;
case 2: strcat(num_name," Two Thousand");break;
case 3: strcat(num_name," Three Thousand");break;
case 4: strcat(num_name," Four Thousand");break;
case 5: strcat(num_name," Five Thousand");break;
case 6: strcat(num_name," Six Thousand");break;
case 7: strcat(num_name," Seven Thousand");break;
case 8: strcat(num_name," Eight Thousand");break;
case 9: strcat(num_name," Nine Thousand");break;
}
num%=1000;
}
if(num>=100)
{
temp=num/100;
switch(temp)
{
case 1: strcat(num_name," One Hundred");break;
case 2: strcat(num_name," Two Hundred");break;
case 3: strcat(num_name," Three Hundred");break;
case 4: strcat(num_name," Four Hundred");break;
case 5: strcat(num_name," Five Hundred");break;
case 6: strcat(num_name," Six Hundred");break;
case 7: strcat(num_name," Seven Hundred");break;
case 8: strcat(num_name," Eight Hundred");break;
case 9: strcat(num_name," Nine Hundred");break;
}
num%=100;
}
if(num>=20)
{
temp=num/10;
switch(temp)
{
case 2: strcat(num_name," Twenty");break;
case 3: strcat(num_name," Thirty");break;
case 4: strcat(num_name," Forty");break;
case 5: strcat(num_name," Fifty");break;
case 6: strcat(num_name," Sixty");break;
case 7: strcat(num_name," Seventy");break;
case 8: strcat(num_name," Eighty");break;
case 9: strcat(num_name," Ninety");break;
}
num%=10;
}
if(num>=10)
{
temp=num%10;
switch(temp)
{
case 1: strcat(num_name," Eleven");break;
case 2: strcat(num_name," Twelve");break;
case 3: strcat(num_name," Thirteen");break;
case 4: strcat(num_name," Forteen");break;
case 5: strcat(num_name," Fifteen");break;
case 6: strcat(num_name," Sixteen");break;
case 7: strcat(num_name," Seventeen");break;
case 8: strcat(num_name," Eighteen");break;
case 9: strcat(num_name," Nineteen");break;
}
goto show;
}
if(num<10)
{
temp=num/1;
switch(temp)
{
case 1: strcat(num_name," One");break;
case 2: strcat(num_name," Two");break;
case 3: strcat(num_name," Three");break;
case 4: strcat(num_name," Four");break;
case 5: strcat(num_name," Five");break;
case 6: strcat(num_name," Six");break;
case 7: strcat(num_name," Seven");break;
case 8: strcat(num_name," Eight");break;
case 9: strcat(num_name," Nine");break;
}
num%=1;
}
show:
cout<<num_name;
getch();
}
No comments:
Post a Comment