Roopa has given a program to her close friend Jhansi in the apartment where she lives.The task is if the number is given it needs to be converted into words.It's like writing the amount in numbers on the cell of the bank challan and then writing it in words.

#include <stdio.h>
#include<string.h>
int main()
{   const char *a[]={ "zero" , "one" , "two" , "three" , "four" , "five" , "six" , "seven" , "eight" , "nine" };

    const char *b[]={ "ten" , "eleven" , "twelve" , "thirteen" , "fourteen" , "fifteen" , "sixteen" , "seventeen" , "eighteen" , "nineteen" };

    const char *c[]={ " " , " " , "twenty" , "thirty" , "forty" , "fifty" , "sixty" , "seventy" , "eighty" , "ninety" };

    //const char *p[]={"hundred" , "thousand" };

    char num[10];

    int l,n,n1;

    scanf("%s",num);

    l=strlen(num);

    if(l==4)

    {       while(l--)

     {          if(l==3&&num[0]!='0')
      {           printf("%s thousand ",a[*num- '0']); }
            if(l==2 && num[1]!='0' && num[2]=='0'&&num[3]=='0')
            {    n=num[1]-48;
                printf("%s hundred ",a[n]);
                break; }
            if(l==2 && num[1]!='0')
            { n=num[1]-48;

                printf("%s hundred ",a[n]);}

            if(l==1)

            { if(num[2]=='0' && num[3]=='0')

                {       printf(" ");

                    break;

                }

                if(num[2]=='0' && num[3]!='0')

                {  n=num[3]-48;

                   printf("%s",a[n]);

                   break; }

                if(num[3!='0' && num[2]!='1']&& num[2]!='0')

                {n=num[2]-48;

                   n1=num[3]-48;

                   printf("and %s %s",c[n],a[n1]);

                   break;}

                 if(num[3]=='0');
               { n=num[2]-48;
                   printf("and %s",c[n]);
                   break;}
                if(num[2]=='1')
                {n=num[3]-48;
                   printf("and %s",b[n]);
                   break;}    }}   
                 return 0;
                 }}

Comments

Popular posts from this blog

Elavenil has a chessboard with N rows and M columns. In one step, he can choose two cells of the chessboard which share a common edge (that has not been cut yet) and cut this edge. Formally, the chessboard is split into two or more pieces if it is possible to partition its cells into two non-empty subsets S1 and S2 (S1∩S2=∅, |S1|+|S2|=NM) such that there is no pair of cells c1,c2 (c1∈S1,c2∈S2) which share a common edge that has not been cut.Elavenil does not want the board to split into two or more pieces. Compute the maximum number of steps he can perform while satisfying this condition.

The Matriculation school have arranged an Annual Day Function.Volunteers have decorated a floor on various places of the school using Rose and Tulip flowers. But one of the coordinators requested the volunteers to rearrange the decoration like a triangular size.Coordinator also told them that tulips flowers need to be positioned at the middle of the roses

Mukesh and Salima was looking to buy Organic Apples in the nearest fruits shop.But Shop Owner mixed the Hybrid apples in that Apple box. After sometimes Mukesh checking the box, he was confused among organic and hybrid apple. He started to count the hybrid apples. Please help to Mukesh Count the total number of hybrid apples in the box.