FaltuTech.Club : Fane of Advanced Logical Thriving Utopian Technical Club

Convert Upto 3 Digit Numbers to Equivalent Word Format (C-Code)

Works only upto 3 digit number



#include  
#include 
  void third_word(int);
void second_word(int);
void second_one(int);
void first_word(int);
void main() {
  int number, first, second, third;
  clrscr();

  printf("Enter the number ");
  scanf("%d", & number); // Enter the number
  first = number / 100; //got first number
  second = (number % 100) / 10; // got second number
  third = (number % 100) % 10; // got third number
  if (first == 0 && second == 0 && third == 0)
    printf("Zero");
  else if (first == 0 && second == 0 && third != 0) {
    third_word(third);
  } else if (first == 0 && second > 1) {
    second_word(second);
    third_word(third);
  } else if (first == 0 && second == 1) {
    second_one(third);
  } else if (first != 0 && second == 0) {
    third_word(first);
    printf(" hundard");
    third_word(third);
  } else if (first != 0 && second == 1) {
    third_word(first);
    printf(" hundard");
    second_one(third);
  } else if (first != 0 && second > 1 && third == 0) {
    third_word(first);
    printf(" hundard");
    second_word(second);
  } else if (first != 0 && second > 1) {
    third_word(first);
    printf(" hundard");
    second_word(second);
    third_word(third);
  }

  getch();
}

void third_word(int input) {
  switch (input) {
  case 0:
    printf("");
    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;
  default:
    printf(" Error");
  }
}

void second_word(int input) {
  switch (input) {
  case 0:
    printf("");
    break;
  case 2:
    printf(" twenty");
    break;
  case 3:
    printf(" thirty");
    break;
  case 4:
    printf(" fourty");
    break;
  case 5:
    printf(" fifty");
    break;
  case 6:
    printf(" sixty");
    break;
  case 7:
    printf(" seventy");
    break;
  case 8:
    printf(" eighty");
    break;
  case 9:
    printf(" ninty");
    break;
  default:
    printf(" Error");
  }
}

void second_one(int input) {
  switch (input) {
  case 0:
    printf(" ten");
    break;
  case 1:
    printf(" eleven");
    break;
  case 2:
    printf(" twelve");
    break;
  case 3:
    printf(" thirteen");
    break;
  case 4:
    printf(" fourteen");
    break;
  case 5:
    printf(" fifteen");
    break;
  case 6:
    printf(" sixteen");
    break;
  case 7:
    printf(" seventeen");
    break;
  case 8:
    printf(" eighteen");
    break;
  case 9:
    printf(" ninteen");
  default:
    printf("Error");
  }
}