1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include<stdio.h>
#include<conio.h>
int main()
{
int num;
system("cls");
printf("Enter a number from -999 to 999: ");
scanf("%d", &num);
int ones = num / 1 % 10;
int tens = num / 10 % 10;
int hund = num / 100 % 10;
const char *one[] = {" ", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
const char *ten[] = {" ", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", "hundred"};
const char *ten2[] = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
if (num < 0)
{
printf("Negative ");
//makes all the digits positive since the number entered is negative
hund = hund - hund * 2;
tens = tens - tens * 2;
ones = ones - ones * 2;
}
if (num >= -999 && num <= 999)
{
if (tens == 1)
{
printf("%s hundred %s", one[hund], ten2[ones]);
}
else
{
printf("%s hundred %s %s", one[hund], ten[tens], one[ones]);
}
}
else
{
printf("Your number is out of range!");
}
getch();
return 0;
}
|