编写一个程序用于接受从终端输入的整数,提取并用英语现实这个数的每一个数字。例如输入932,显示:
nine
three
two
#import <Foundation/Foundation.h>
int main (int argc,const char * argv[])
{
@autoreleasepool {
int number, numberStorage, leftDigit, index, indexStorage;
NSLog(@"Please, input the number that you would like to convert");
scanf(" %i", &number);
/*----Entering nest statements and loops section----*/
if ( number != 0 ) // if 'number' equals zero skip loops and output "Zero"
{
numberStorage = number;
/*----Loop to obtain the number of digits entered by user and store in variable 'index'----*/
for( index = 0; number !=0; ++index )
number /= 10;
indexStorage = index;
number = numberStorage; // reset 'number' to the original input value
/*----Loop to extract and printout each digit from left to right----*/
for ( int i =1; i <= index; i++ )
{
while (indexStorage != 0 )
{
leftDigit = number % 10;
number /= 10;
indexStorage--;
}
switch (leftDigit)
{
case 0:
NSLog(@"Zero");
break;
case 1:
NSLog(@"One");
break;
case 2:
NSLog(@"Two");
break;
case 3:
NSLog(@"Three");
break;
case 4:
NSLog(@"Four");
break;
case 5:
NSLog(@"Five");
break;
case 6:
NSLog(@"Six");
break;
case 7:
NSLog(@"Seven");
break;
case 8:
NSLog(@"Eight");
break;
case 9:
NSLog(@"Nine");
break;
default:
break;
}
indexStorage = index - i; // reset 'indexStorage' to orginal 'index' value minus 'i'
number = numberStorage; // reset 'number' to orginal user input value
}
/*----perform loop until 'i' is equal to index----*/
}
else
NSLog(@"Zero");
}
return 0;
}