https://blog.csdn.net/sinat_36161667/article/details/80786754
bool increment(char * array, int n) {
int sIndex = n-1;
array[sIndex] = array[sIndex] + 1;
int extra = 0;
for (int i = sIndex; i>=0; i--) {
int curIndexNum = array[i] - '0' + extra;
array[i] = array[i] + extra;
if (10 == curIndexNum) {
// 达到进位
if (i == 0) {
// 超精度了
return true;
}
array[i] = '0';
extra = 1;
}
else {
// 没到进位,直接返回就好了
return false;
}
}
return false;
}
void printN(int n) {
if ( n <= 0 ) {
return;
}
char *array = (char *)malloc(sizeof(char) * n+1);
memset(array, '0', n);
while ( !increment(array, n) ) {
NSString *string_content = [[NSString alloc] initWithCString:(const char*)array
encoding:NSASCIIStringEncoding];
NSLog(@"%@\r\n",string_content);
}
}
dave-li 发布了76 篇原创文章 · 获赞 68 · 访问量 8万+ 私信 关注