943,592 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 463
  • C RSS
Mar 10th, 2009
0

numeric to figures

Expand Post »
hello
Is there any way to change numeric to figures?
for example if the user input is 134, the program output must be one three four.


thanks in advance,
Bluebird
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bluebird is offline Offline
58 posts
since Nov 2006
Mar 10th, 2009
0

Re: numeric to figures

moved. You didn't say what programming language so I assumed C. Next time don't post tech questions in Geek's Lounge.
Last edited by Ancient Dragon; Mar 10th, 2009 at 3:57 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Mar 10th, 2009
0

Re: numeric to figures

Yes.
I intended to post in c. I don't know how it was get to the Geek's Lounge.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bluebird is offline Offline
58 posts
since Nov 2006
Mar 10th, 2009
0

Re: numeric to figures

One way to do it is to make an array of strings that contain the words for each number, then index into that array with each digit of the integer. To get each digit of the integer you will need a loop, use the % operator, and the / (divide) operator.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Mar 10th, 2009
0

Re: numeric to figures

divide by 10 to erase the right most digit use % 10 to single out the right most digit
Reputation Points: 17
Solved Threads: 3
Junior Poster
Dewey1040 is offline Offline
126 posts
since Dec 2008
Mar 14th, 2009
0

Re: numeric to figures

Click to Expand / Collapse  Quote originally posted by bluebird ...
hello
Is there any way to change numeric to figures?
for example if the user input is 134, the program output must be one three four.


thanks in advance,
Bluebird
Check it out..............
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. void main()
  5. {
  6. int num,numcnt,div,i=1,n=0;
  7. char str[10][10];
  8. clrscr();
  9. printf("Enter a num :");
  10. scanf("%d",&num);
  11. numcnt=num;
  12. while(numcnt>0)
  13. {
  14. numcnt=numcnt/10;
  15. i=i*10;
  16. }
  17. while(num>0)
  18. {
  19. i=i/10;
  20. div=num/i;
  21. num=num%i;
  22. if(div==0)
  23. strcpy(str[n],"Zero");
  24. else if(div==1)
  25. strcpy(str[n],"One");
  26. else if(div==2)
  27. strcpy(str[n],"Two");
  28. else if(div==3)
  29. strcpy(str[n],"Three");
  30. else if(div==4)
  31. strcpy(str[n],"Four");
  32. else if(div==5)
  33. strcpy(str[n],"Five");
  34. else if(div==6)
  35. strcpy(str[n],"Six");
  36. else if(div==7)
  37. strcpy(str[n],"Seven");
  38. else if(div==8)
  39. strcpy(str[n],"Eight");
  40. else if(div==9)
  41. strcpy(str[n],"Nine");
  42. n++;
  43. }
  44. for(i=0;i<n;i++)
  45. printf("%s ",str[i]);
  46. getch();
  47. }
Reputation Points: 9
Solved Threads: 1
Newbie Poster
rajenpandit is offline Offline
13 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Custom pascal triangle ?
Next Thread in C Forum Timeline: Rereading files in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC