请问怎样用C++使用递归调用方法将一个n位整数转换成字符串

[复制链接]
查看11 | 回复2 | 2012-11-29 21:32:56 | 显示全部楼层 |阅读模式
#include void ntochar(int n, char* ch){ static int i = 0; if (n != 0) {ntochar(n / 10, ch);ch[i++] = n % 10 + '0';ch = '\0'; }} int main(){ char ch[100] = {0}; int n; printf("enter number: "); scanf("%d", &n); ntochar(n, ch); printf("%s\n", ch); return 0;}...
回复

使用道具 举报

千问 | 2012-11-29 21:32:56 | 显示全部楼层
void adjust(int n){
if(n==0) return;
else if(n<10) printf("%c",n+'0');
else{
printf("%c",n%10+'0');
n=n/10;
}}...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行