• Write a program to input a digit and print it in words
  • C program to print number in words using switch cas.
  • Now we will see how to convert number /digits in to words in C programming.
  • Get the input from the user using Scanf() function.
  • Using while loop and % operator and get the each number and use switch case to print corresponding word for the current number.



Program #1: write a program in c that reads the digits and then converts them into words

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(int argc, char *argv[])
  4. {
  5.  int number,i=0,j,digit;
  6.     char * word[1000];
  7.  
  8.     printf("Enter any integer to print that in words: ");
  9.     scanf("%d",&number);
  10.  
  11.     while(number){
  12.  
  13.     digit = number %10;
  14.     number = number /10;
  15.  
  16.          switch(digit){
  17.              case 0: word[i++] = "zero"; break;
  18.              case 1: word[i++] = "one"; break;
  19.              case 2: word[i++] = "two"; break;
  20.              case 3: word[i++] = "three"; break;
  21.              case 4: word[i++] = "four"; break;
  22.              case 5: word[i++] = "five"; break;
  23.              case 6: word[i++] = "six"; break;
  24.              case 7: word[i++] = "seven"; break;
  25.              case 8: word[i++] = "eight"; break;
  26.              case 9: word[i++] = "nine"; break;
  27.  
  28.         }
  29.     }
  30.    
  31.     for(j=i-1;j>=0;j--){
  32.          printf("%s ",word[j]);
  33.     }
  34.  return 0;
  35. }
  
Output:


print numbers in words c program

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu