Contact Learn C
Copy

Program 290: Print Given Money or Value in Words

Program 290: Print Given Money or Value in Words

#include<stdio.h>
main()
{
 int i,j,k=0,value,count,a[10],dummy;
 char *ones[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
 char *temp[]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
 char *tens[]={"-","-","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
 //hundreds are same as ones
 printf("Enter Value upto 6 digits to get in Words\n");
 dummy=value;
 scanf("%d",&value);
 while(value>0)
 {
  i=value%10;
  a[k]=i;
  k++;
  value/=10;
 }
 //Here if 12345 is given then a[0]=5,a[1]=4 and soon then last but one digit will be at a[1]
 int totalDigits=k-1;
 if(totalDigits<6)
   {
     for(i=totalDigits;i>=0;i--)
     {
      if(i==5 && a[i]!=0)
      {
      printf("%s lakh ",ones[a[i]]);
      }
      if(i==4 || i==3)
      {
       //Start
       if(i==4 && a[i]==0)
       {
        printf("%s thousand ",ones[a[i-1]]);
        i--;
       }
       else if(i==4 && a[i]==1)
       {
        printf("%s thousand ",temp[a[i-1]]);
        i--;
       }
       else if(i==4)
       {
        printf("%s ",tens[a[i]]);
       }
       else
       {
        printf("%s thousand ",ones[a[i]]);
       }
          //end 
      }
      if(i==2 && a[i]!=0)
      {
          printf("%s hundred and ",ones[a[i]]); 
      }
      if(i==2 && a[i]==0)
      {
       printf("and ");
      }
      if(i==1 || i==0)
      {
       if(i==1 && a[i]==0)
       {
        printf("%s only\n",ones[a[i-1]]);
        i--;
        break;
       }
          if(i==1 && a[i]==1)
       {
        printf("%s only\n",temp[a[i-1]]);
        i--;
        break;
       }
          if(i==1 && a[i]!=1 && a[i]!=0)
       {
        printf("%s ",tens[a[i]]);
       }
       if(i==0 && a[i]!=0)
       {
        printf("%s only\n",ones[a[i]]);
       }
      }
     }
   }
   else
   {
    printf("Enter only upto 6 digits\n");
   }
}
Explanation:

//Coming Soon

Output:

Print Given Money or Value in Words


Print Given Money or Value in Words using C

Print Given Money or Value in Words using C

Print Given Money or Value in Words using C

Print Given Money or Value in Words using C



15 comments:

  1. Another option is to become a copywriter or copy editor where you're paid to write copies in an effort to promote products and services. Chris Harrold

    ReplyDelete
  2. Wonderful article. Fascinating to read. I love to read such an excellent article. Thanks! It has made my task more and extra easy. Keep rocking. dark0de market url

    ReplyDelete
  3. Love to read it,Waiting For More new Update and I Already Read your Recent Post its Great Thanks. dark0de market link

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. wow,
    Great Post, I appreciate your effort if anyone want to know about the sublimation printer cricut visit given link. Thank regards Surveyfor

    ReplyDelete
  6. I really appreciate your work, if anyone is interested in buying affordable monitors click on Monitors Under 200 USD

    ReplyDelete
  7. Great post, Thank you so much for sharing such wonderful piece that is really informative for us smokesandvape

    ReplyDelete
  8. I really appreciate your work, if anyone is interested in buying affordable for usaffordableinsurancenow

    ReplyDelete
  9. Fantastic article, many thanks for sharing such an informative piece with us. you can also check Adobe Acrobat Crack

    ReplyDelete
  10. Great work! It is really helpful for newbies who are interested in learning programming, you can also check Liquid Herbal Incense

    ReplyDelete
  11. Great you have done your job nicely. You can also check Pure THCP Cartridges

    ReplyDelete
  12. Fantastic article, many thanks for sharing such an informative piece with us. you can also check Who Uses Visa Provisioning Service

    ReplyDelete
  13. That's Awesome! you have done great work. Really apreciated.

    ReplyDelete
  14. The Lando Norris Triple Crown phone case combines style and fandom, showcasing the dynamic driver's name and achievements in Formula 1, making it a perfect accessory for fans to protect their phones while displaying their admiration for Norris and his pursuit of racing excellence.

    ReplyDelete

Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide