我需要知道如何以正確的順序將整數分成數字,例如, 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;
}
結帳這個相關[問題](http://stackoverflow.com/questions/3377510/convert-number-to-words-in- objective-c)一旦你開始對這種語言和它的API感到舒服。你現在開始一個好的開始。 – Anurag