All for Joomla All for Webmasters

C Program to convert Number in Characters

Number in characters conversion: In c language, we can easily convert number in characters by the help of loop and switch case. In this program, we are taking input from the user and iterating this number until it is 0. While iteration, we are dividing it by 10 and the remainder is passed in switch case to get the word for the number.

Let’s see the c program to convert number in characters.

  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. long int n,sum=0,r;
  6. clrscr();
  7. printf(“enter the number=”);
  8. scanf(“%ld”,&n);
  9. while(n>0)
  10. {
  11. r=n%10;
  12. sum=sum*10+r;
  13. n=n/10;
  14. }
  15. n=sum;
  16. while(n>0)
  17. {
  18. r=n%10;
  19. switch(r)
  20. {
  21. case 1:
  22. printf(“one “);
  23. break;
  24. case 2:
  25. printf(“two “);
  26. break;
  27. case 3:
  28. printf(“three “);
  29. break;
  30. case 4:
  31. printf(“four “);
  32. break;
  33. case 5:
  34. printf(“five “);
  35. break;
  36. case 6:
  37. printf(“six “);
  38. break;
  39. case 7:
  40. printf(“seven “);
  41. break;
  42. case 8:
  43. printf(“eight “);
  44. break;
  45. case 9:
  46. printf(“nine “);
  47. break;
  48. case 0:
  49. printf(“zero “);
  50. break;
  51. default:
  52. printf(“tttt”);
  53. break;
  54. }
  55. n=n/10;
  56. }
  57. getch();
  58. }

Output:

enter the number=4321
four three two one
PinIt
submit to reddit

Leave a Reply

Top