我需要知道如何以正确的顺序将整数拆分为数字,例如 1234 显示为 1 2 3 4。我希望它拆分整数并将数字显示为单词,所以 1234 = 1 2 3 4 = 一二三四。这就是我到目前为止所得到的。它拆分一个整数并将数字显示为单词,但它们的顺序相反。对不起,如果它有点乱。另外我才刚刚开始学习目标 c,所以我还不知道数组和所有这些东西。
int number, right_digit, counter;
counter = 1;
NSLog(@"Enter your number");
while (counter != 0) {
scanf("%i", &number);
do {
right_digit = number % 10;
number /= 10;
if (right_digit == 1)
NSLog(@"one");
else if (right_digit == 2)
NSLog(@"two");
else if (right_digit == 3)
NSLog(@"three");
else if (right_digit == 4)
NSLog(@"four");
else if (right_digit == 5)
NSLog(@"five");
else if (right_digit == 6)
NSLog(@"six");
else if (right_digit == 7)
NSLog(@"seven");
else if (right_digit == 8)
NSLog(@"eight");
else if (right_digit == 9)
NSLog(@"nine");
else if (right_digit == 0)
NSLog(@"zero");
}
while (number != 0);
}
}
return 0;
}