I fixed some bugs (uninitialized variables). Please note: you should handle the digit
0
(zero) too.
#include <math.h>
#include <stdio.h>
void show_number(int number)
{
int counter = 0;
int i, temp, digit, x, ten;
if (number > 9) {
temp = number;
while (temp >= 1 ) {
temp = temp / 10;
++counter;
}
for (i = 1; i <= (counter - 1); i++) {
digit = (int)number / pow(10.0, (counter - i));
if (digit == 9) {
printf ("nine ");
}
else if (digit == 8) {
printf ("eight ");
}
else if (digit == 7) {
printf ("seven ");
}
else if (digit == 6) {
printf ("six ");
}
else if (digit == 5) {
printf ("five ");
}
else if (digit == 4) {
printf ("four ");
}
else if (digit == 3) {
printf ("three ");
}
else if (digit == 2) {
printf ("two ");
}
else if (digit == 1) {
printf ("one ");
}
x = 1;
ten =1;
for (x = 1; x <= counter - i; x++) {
ten = ten * 10;
}
number = number % ten;
}
}
digit = number;
if (digit > 0 && digit < 10) {
if (digit == 9) {
printf ("nine ");
}
else if (digit == 8) {
printf ("eight ");
}
else if (digit == 7) {
printf ("seven ");
}
else if (digit == 6) {
printf ("six ");
}
else if (digit == 5) {
printf ("five ");
}
else if (digit == 4) {
printf ("four ");
}
else if (digit == 3) {
printf ("three ");
}
else if (digit == 2) {
printf ("two ");
}
else if (digit == 1) {
printf ("one ");
}
}
}