Wednesday 12 September 2012

convert integer number into alphbet words..!

#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int a,b,num,c,d,e,f;
  //int p,num,thousand,hundred,ten,unit;
  cout<<"Enter the numbers in range(0-9999)=";
  cin>>num;
  if(num>=0&&num<=19)
  {
  if(num==0)
  cout<<"zero";
  if(num==1)
  cout<<"one";
  if(num==2)
  cout<<"two";
  if(num==3)
  cout<<"three";
  if(num==4)
  cout<<"four";
  if(num==5)
  cout<<"five";
  if(num==6)
  cout<<"six";
  if(num==7)
  cout<<"seven";
  if(num==8)
  cout<<"eigth";
  if(num==9)
  cout<<"nine";
  if(num==10)
  cout<<"ten";
  if(num==11)
  cout<<"eleven";
  if(num==12)
  cout<<"twelve";
  if(num==13)
  cout<<"thirteen";
  if(num==14)
  cout<<"forteen";
  if(num==15)
  cout<<"fifteen";
  if(num==16)
  cout<<"sixteen";
  if(num==17)
  cout<<"seventeen";
  if(num==18)
  cout<<"eigtheen";
  if(num==19)
  cout<<"ningteen";
  }


  else if(num>=20&&num<=99)
  {
  a=num/10;
  b=num%10;
  if(a==2)
  cout<<"twenty";
  if(a==3)
  cout<<"thirty";
  if(a==4)
  cout<<"forty";
  if(a==5)
  cout<<"fifty";
  if(a==6)
  cout<<"sixty";
  if(a==7)
  cout<<"seventy";
  if(a==8)
  cout<<"eigthy";
  if(a==9)
  cout<<"ninty";
  if(b==0)
  cout<<"";
  if(b==1)
  cout<<" one";
  if(b==2)
  cout<<" two";
  if(b==3)
  cout<<" three";
  if(b==4)
  cout<<" four";
  if(b==5)
  cout<<" five";
  if(b==6)
  cout<<" six";
  if(b==7)
  cout<<" seven";
  if(b==8)
  cout<<" eigth";
  if(b==9)
  cout<<" nine";
  }


  else if(num>=100&&num<=999)
  {
  a=num/100;
  b=num%100;
  c=b/10;
  d=b%10;
  if(a==1)
  cout<<" one hundred";
  if(a==2)
  cout<<" two hundred";
  if(a==3)
  cout<<" three hundred";
  if(a==4)
  cout<<" four hundred";
  if(a==5)
  cout<<" five hundred";
  if(a==6)
  cout<<" six hundred";
  if(a==7)
  cout<<" seven hundred";
  if(a==8)
  cout<<" eigth hundred";
  if(a==9)
  cout<<" nine hundred";
  if(c==0)
  {
  if(d==0)
  cout<<"";
  if(d==1)
  cout<<" and one";
  if(d==2)
  cout<<" and two";
  if(d==3)
  cout<<" and three";
  if(d==4)
  cout<<" and four";
  if(d==5)
  cout<<" and five";
  if(d==6)
  cout<<" and six";
  if(d==7)
  cout<<" and seven";
  if(d==8)
  cout<<" and eigth";
  if(d==9)
  cout<<" and nine";
  }
  if(c==1)
  {
  if(d==0)
  cout<<" and ten";
  if(d==1)
  cout<<" and eleven";
  if(d==2)
  cout<<" and twelve";
  if(d==3)
  cout<<" and thirteen";
  if(d==4)
  cout<<" and forteen";
  if(d==5)
  cout<<" and fifteen";
  if(d==6)
  cout<<" and sixteen";
  if(d==7)
  cout<<" and seventeen";
  if(d==8)
  cout<<" and eigtheen";
  if(d==9)
  cout<<" and ningteen";
    }
  if(b>=20)
  {
   if(c==2)
  cout<<" and twenty";
  if(c==3)
  cout<<" and thirty";
  if(c==4)
  cout<<" and forty";
  if(c==5)
  cout<<" and fifty";
  if(c==6)
  cout<<" and sixty";
  if(c==7)
  cout<<" and seventy";
  if(c==8)
  cout<<" and eigthy";
  if(c==9)
  cout<<" and ninty";
  if(d==0)
  cout<<"";
  if(d==1)
  cout<<" one";
  if(d==2)
  cout<<" two";
  if(d==3)
  cout<<" three";
  if(d==4)
  cout<<" four";
  if(d==5)
  cout<<" five";
  if(d==6)
  cout<<" six";
  if(d==7)
  cout<<" seven";
  if(d==8)
  cout<<" eigth";
  if(d==9)
  cout<<" nine";
    }
    }


    else if(num>=1000&&num<=9999)
    {
    a=num/1000;
    b=num%1000;
    c=b/100;
    d=b%100;
    e=d/10;
    f=d%10;
    if(a==1)
    cout<<" one thousand";
    if(a==2)
    cout<<" two thousand";
    if(a==3)
    cout<<" three thousand";
    if(a==4)
    cout<<" four thousand";
    if(a==5)
    cout<<" five thousand";
    if(a==6)
    cout<<" six thousand";
    if(a==7)
    cout<<" seven thousand";
    if(a==8)
    cout<<" eigth thousand";
    if(a==9)
    cout<<" nine thousand";
    if(c==0)
    cout<<"";
    if(c==1)

  cout<<" one hundred";
  if(c==2)
  cout<<" two hundred";
  if(c==3)
  cout<<" three hundred";
  if(c==4)
  cout<<" four hundred";
  if(c==5)
  cout<<" five hundred";
  if(c==6)
  cout<<" six hundred";
  if(c==7)
  cout<<" seven hundred";
  if(c==8)
  cout<<" eigth hundred";
  if(c==9)
  cout<<" nine hundred";
  if(e==0)
  {
  if(f==0)
  cout<<"";
  if(f==1)
  cout<<" and one";
  if(f==2)
  cout<<" and two";
  if(f==3)
  cout<<" and three";
  if(f==4)
  cout<<" and four";
  if(f==5)
  cout<<" and five";
  if(f==6)
  cout<<" and six";
  if(f==7)
  cout<<" and seven";
  if(f==8)
  cout<<" and eigth";
  if(f==9)
  cout<<" and nine";
  }

  if(e==1)
  {
  if(f==0)
  cout<<" and ten";
  if(f==1)
  cout<<" and eleven";
  if(f==2)
  cout<<" and twelve";
  if(f==3)
  cout<<" and thirteen";
  if(f==4)
  cout<<" and forteen";
  if(f==5)
  cout<<" and fifteen";
  if(f==6)
  cout<<" and sixteen";
  if(f==7)
  cout<<" and seventeen";
  if(f==8)
  cout<<" and eigtheen";
  if(f==9)
  cout<<" and ningteen";
    }
  if(d>=20)
  {
   if(e==2)
  cout<<" and twenty";
  if(e==3)
  cout<<" and thirty";
  if(e==4)
  cout<<" and forty";
  if(e==5)
  cout<<" and fifty";
  if(e==6)
  cout<<" and sixty";
  if(e==7)
  cout<<" and seventy";
  if(e==8)
  cout<<" and eigthy";
  if(e==9)
  cout<<" and ninty";
  if(f==0)
  cout<<"";
  if(f==1)
  cout<<" one";
  if(f==2)
  cout<<" two";
  if(f==3)
  cout<<" three";
  if(f==4)
  cout<<" four";
  if(f==5)
  cout<<" five";
  if(f==6)
  cout<<" six";
  if(f==7)
  cout<<" seven";
  if(f==8)
  cout<<" eigth";
  if(f==9)
  cout<<" nine";
    }
    }
  getch();

  }


No comments:

Post a Comment