Header Ads

Learn Together, Stay Connected.

Spell Out a number-C++

#include<bits/stdc++.h>

using namespace std;

int main()
{
    char a1[10][10]={"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
    char a2[10][10]={"Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
    char a3[10]="Hundred";
    char a4[10][10]={"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
	int n;
    
	while(1)
	{
	cin>>n;
	int temp;
	
	temp=n/100;

	if(temp>0) cout<<a1[temp]<<" "<<a3<<" ";
	
	temp=(n%100)/10;
	if(temp==1)
	 cout<<a4[n%10]<<endl;
	  
	if(temp>1) cout<<a2[temp-1]<<" ";
	if(temp!=1)
	{
	temp=(n%10);
	if(temp>0) cout<<a1[temp];
	}
    cout<<endl;
	}
	return 0;
}

No comments

Theme images by Dizzo. Powered by Blogger.