Program To Convert Upto 9 Digit Number To Words

#include  stdio.h       // friend's  this blog page considering this including file as html tags so why 
#include  conio.h       // I removed brackets.
int val(int);
void main()
{
    long n;
    int i,m,j=0,k,l;
    char *a[20][20]={{"Zero","","","","","","","","",},{"","One","Ten","One Hundred","One Thousand","Ten Thousand","One Lakh","Ten Lakh","One Crore","Ten Crore"},
                     {"","Two","Twenty","Two Hundred","Two Thousand","Twenty Thousand","Two Lakh","Twenty Lakh","Two Crore","Twenty Crore"},
                     {"","Three","Thirty","Three Hundred","Three Thousand","Thirty Thousand","Three Lakh","Thirty Lakh","Three Crore","Thirty Crore"},
                     {"","Four","Fourty","Four Hundred","Four Thousand","Foutry Thousand","Four Lakh","Fourty Lakh","Four Crore","Fourty Crore"},
                     {"","Five","Fifty","Five Hundred","Five Thousand","Fifty Thousand","Five Lakh","Fifty Lakh","Five Crore","Fifty Crore"},
                     {"","Six","Sixty","Six Hundred","Six Thousand","Sixty Thousand","Six Lakh","Sixty Lakh","Six Crore","Sixty Crore"},
                     {"","Seven","Seventy","Seven Hundred","Seven Thousand","Seventy Thousand","Seven Lakh","Seventy Lakh","Seven Crore","Seventy Crore"},
                     {"","Eight","Eighty","Eight Hundred","Eight Thousand","Eighty Thousand","Eight Lakh","Eighty Lakh","Eight Crore","Eight Crore"},
                     {"","Nine","Ninty","Nine Hundred","Nine Thousand","Ninty Thousand","Nine Lakh","Ninty Lakh","Nine Crore","Ninty Crore"}};
    char *b[15][10]={{"","","","",""},
                    {"","Eleven","Eleven Thousand","Eleven Lakh","Eleven Crore"},
                    {"","Twelve","Twelve Thousand","Twelve Lakh","Twelve Crore"},                      
                    {"","Thirteen","Thirteen Thousand","Thirteen Lakh","Thirteen Crore"},
                    {"","Fourteen","Fourteen Thousand","Fourteen Lakh","Fourteen Crore"},
                    {"","Fifteen","Fifteen Thousand","Fifteen Lakh","Fifteen Crore"},
                    {"","Sixteen","Sixteen Thousand","Sixteen Lakh","Sixteen Crore"},
                    {"","Seventeen","Seventeen Thousand","Seventeen Lakh","Seventeen Crore"},
                    {"","Eighteen","Eighteen Thousand","Eighteen Lakh","Eighteen Crore"},
                    {"","Ninteen","Ninteen Thousand","Ninteen Lakh","Ninteen Crore"}};

  printf("Enter Your Number=");
    scanf("%ld",&n);
    for(i=0;n>0;n=n/10)        //For Reverse Number
    {
        i=i*10;
        i=i+(n%10);
        j++;
    }
    m=i;
    for(i=0;m>0;m=m/10)            //for getting single digit o print
    {
        i=i+(m%10);
        if((j==9||j==7||j==5) && i==1)        //for at position ,9,7,5 starting with 1
        {    k=i;
            m=m/10;
            i=0;
            i=i+(m%10);
            if(i!=0)            //for at position 8,6,4 not having 0., eleven - ninteen.
            {
                if(j==9)
                {
                    printf("%s ",b[i][4]);
                   }
                else if(j==7)
                {
                    printf("%s ",b[i][3]);
                 }  
                else if(j==5)
                {  
                    printf("%s ",b[i][2]);
                   }
            }
            else                                //for at position 8,6,4 having 0.,ten-ninty
               {
                printf("%s ",a[k][j]);
            }
            i=0;
             j-=2;
        }
        else if((j==9||j==7||j==5) && i!=1 && i!=0)        //for at position ,9,7,5 starting with greater than 1.
        {
                l=val(m);                                //getting value from function
                if(l!=0)
                {
                    printf("%s ",a[i][2]);
                }
                else
                {
                    printf("%s",a[i][j]);  
                }
                j--;
                i=0;
        }
        else if(j==2 && (i==1||i==0))                //for last two digit
        {
            if(i==0)                                //for second last digit is equal to 0
            {
                i=(m/10);
                printf("%s",a[i][1]);
            }
            else                                    //for second last digit is equal to 1
            {
                i=(m/10);
                printf("%s",b[i][1]);
            }
            i=j=0;
        }
        else                                        //for ptinting as per position,less than 9999
        {
            printf("%s ",a[i][j]);
            j--;
            i=0;
        }
    }
      
}
int val(int f)
{
    int p=0;
    f=f/10;
    p=p+(f%10);
    return p;
}
/* Output:
Enter Your Number=102365049
Ten Crore Twenty Three Lakh Sixty Five Thousand  Fourty Nine.
--------------------------------
*/

Comments

Popular posts from this blog

Program To Convert Number In Word To Digit In C Language

Program To Convert Digit To Word.