کد:
#include <iostream.h>
#include <conio.h>
int enter();
int numbers(long int);
void convert(int);
void process(int);
const d=5;
int digit[d],count;
char str1[10][10]={" ","Yek","Do","Se","Chahar","Panj","Shesh","Haft","Hasht","Noh"};
char str2[10][10]={"Dah","Yazdah","Davazdah","Sizdah","Chahardah","Panezdah","Shanezdah","Hefdah","Hejdah","Noozdah"};
char str3[10][10]={" ","Dah","Bist","Si","Chehel","Panjah","Shast","Haftad","Hashtad","Navad"};
char str4[10][10]={" ","Sad","Devist","Sisad","Chaharsad","Pansad","Sheshsad","Haftsad","Hashtsad","Nohsad"};
char str5[d][10]={"","Hezar","Milion","Milliard","Trilliard"};
int first[100];
int check(int i);
void main()
{
clrscr();
int num;
cout<<" Convert Digits to Text (Farsi Version) \n\n";
cout<< "enter number with less than "<< (d*3) <<" digits: ";
num=enter();
process(num);
cout << "\n\n there is "<<num <<" digits entered \n\n - - - - - - - - - - - - - - - - - - -\n \n";
cout << (num>d*3?"~... too big number !!":"");
if(num<=d*3)
for (int i=count-1;i>=0;i--)
{
if(digit[i]>0)
{
convert(digit[i]);
cout <<str5[i];
cout <<(check(i)?"o ,":" ,");
}
}
getch();
}
void convert(int n)
{
int a;
a=n/100;
if(a>0)
cout<< str4[a] << (n%100>0?"o ":"");
n%=100;
if (n>=20)
cout<< str3[n/10] << (n%10>0?"o ":" ") << str1[n%10] << ' ';
else if (n<20 && n>=10)
cout<< str2[n%10] << ' ' ;
else if (n<10)
cout << str1[n] << ' ';
}
int enter()
{
int i;
i=getch();
int num=0;
while (i!=13)
{
if (i > 47 && i<58 || i==8)
{
if (i==8 && num>0)
{
num--;
first[num]=0;
putch(i);
putch(' ');
}
else
{
first[num]=i-'0';
num++;
}
putch(i);
}
i=getch();
}
return (num);
}
void process(int num)
{
int k=1,m=0,i;
for(i=num-1;i>=0;i--)
{
m=first[i]*k+m;
k*=10;
if (k>100)
{
digit[count]=m;
m=0;k=1;;
count++;
}
}
if(m>0)
{
digit[count]=m;
count++;
}
}
int check(int i)
{
int k=0;
for (int j=i-1;j>=0;j--)
if (digit[j]>0)
k=1;
return k;
}