Write a program that accepts a positive integer and prints the number in such a way that every digit will be replaced by the corresponding word. eg. 6485—> six four eight five

#include<stdio.h>
#include<conio.h>
/*hint : reverse the no, seperate digits of reversed no and apply switch on each digit*/
int main()
{
int n,rev=0,digit,y,d;
clrscr();
printf("Enter one positive integern");
scanf("%d",&n);
if(n<=0)
printf("Invalid datan"); //to check if input is a positive no or not
else
{
  while(n>0)  //to obtain each digit
  {
    digit=n%10;
    rev=rev*10+digit; //to obtain the reverse no as digits are seperated from units digit towards the higher place digit
    n=n/10;

  }
  y=rev;
  while(y>0)
  {
    d=y%10;   //obtain each digit of the reversed no
    switch(d) //apply switch case on each digit to print corresponding word
    {
      case 0: printf("zero "); break;
      case 1: printf("one "); break;
      case 2: printf("two "); break;
      case 3: printf("three "); break;
      case 4: printf("four "); break;
      case 5: printf("five "); break;
      case 6: printf("six "); break;
      case 7: printf("seven "); break;
      case 8: printf("eight "); break;
      case 9: printf("nine "); break;
    }
    y=y/10; //no obtained after removal of one digit in each step
  }
}
getch();
return 0;
}

 

Please follow and like us:

2 thoughts on “Write a program that accepts a positive integer and prints the number in such a way that every digit will be replaced by the corresponding word. eg. 6485—> six four eight five

Leave a Comment