C程序設(shè)計語言 (第二版) 練習(xí) 4-12
練習(xí) 4-12 運用printd函數(shù)的設(shè)計思想編寫一個遞歸版本的itoa函數(shù),即通過遞歸調(diào)用把整數(shù)轉(zhuǎn)換為字符串。
注意:代碼在win32控制臺運行,在不同的IDE環(huán)境下,有部分可能需要變更。
IDE工具:Visual Studio 2010
?文章來源地址http://www.zghlxwxcb.cn/news/detail-800197.html
代碼塊:
#include <stdio.h>
#include <stdlib.h>
void itoa(int n, char s[]){
static int i = 0;
if(n < 0){
s[i++] = '-';
n = -n;
}
if(n / 10){
itoa(n / 10, s);
}
s[i++] = n % 10 + '0';
s[i] = '\0';
}
int main(){
int n = -2356;
char s[60];
itoa(n, s);
printf("%s\n", s);
system("pause");
return 0;
}
文章來源:http://www.zghlxwxcb.cn/news/detail-800197.html
到了這里,關(guān)于C //練習(xí) 4-12 運用printd函數(shù)的設(shè)計思想編寫一個遞歸版本的itoa函數(shù),即通過遞歸調(diào)用把整數(shù)轉(zhuǎn)換為字符串。的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!