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

Output:

enter the number=4321
four three two one
Previous Post Next Post