tgoop.com/toptech11/56
Last Update:
برنامج تحويل الاعداد الى نصوص باستخدام c++
#include<iostream>
#include<string>
using namespace std;
int main()
{
string digits[20]={"Zero ","One ","Two ","Three ","Four ","Five ",
"Six ","Seven ","Eight ","Nine ","Ten ","Eleven ","Twelve ",
"Thirteen ","Fourteen ","Fifteen ","Sixteen ","Seventeen ",
"Eighteen ","Nineteen "};
string tens[8]={"Twenty ","Thirty ","Forty ","Fifty ","Sixty ","Seventy ","Eighty ","Ninety "};
int n;
cout << "Insert a Number : ";
cin >> n;
int num[9];
for(int i=8 ; i>=0 ; i--)
{
num[i]=n%10;
n=n/10;
}
bool a=(num[0]+num[1]+num[2] > 0);
bool b=(num[3]+num[4]+num[5] > 0);
bool c=(num[6]+num[7]+num[8] > 0);
cout<<"\n";
for(int k=0 ; k<=6 ; k+=3)
{
if(num[k] != 0)
cout << digits[num[k]] << "Hundred ";
if(num[k+1] > 1)
cout << tens[num[k+1] - 2];
if(num[k+1] == 1)
cout << digits[10 * num[k+1] + num[k+2]];
if(num[k+1]!=1 && num[k+2]!= 0)
cout << digits[num[k+2]];
if(k==0 && a)
{
cout << "Million ";
if(b || c) cout << ",\n";
}
if(k==3 && b)
{
cout << "Thousand ";
if(c) cout << ",\n";
}
}
cout << "\n\n";
return 0;
}
BY TOP-TECH
Share with your friend now:
tgoop.com/toptech11/56