工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 3513|回复: 3

怎样在c语言里把数字转成字符串?

[复制链接]
发表于 2007-1-5 20:16 | 显示全部楼层 |阅读模式
问题同上,谢谢!

#include <stdio.h>
void main()
{void convert(int n);
int number;
printf("input an integer:");
scanf("%d%,&number") ;
printf("\noutputs:");
if(number<0)
    {putchar('-');
    number=-number;}
convert('\n');
}
void convert(int n)
{int i;
if((i=n/10)!=0)
convert(i);
putchar((n%10)!=0);
getch();
}

这是课本给出的答案,但我运行果,得不出结果!!
题目要求用函数递归!!

[ 本帖最后由 Ja5oN 于 2007-1-5 20:19 编辑 ]
发表于 2007-1-5 22:14 | 显示全部楼层
itoa 函数
具体可以GOOGLE下……
回复

使用道具 举报

发表于 2007-1-5 22:16 | 显示全部楼层
或者你可以自己写一个

原理很简单:
貌似本版曾写过


只写了atoi 从字符到数字

https://www.gdutbbs.com/viewthread.php?tid=77284&highlight=%BF%E2%BA%AF%CA%FD

[ 本帖最后由 iptton 于 2007-1-5 22:18 编辑 ]
回复

使用道具 举报

发表于 2007-1-6 16:05 | 显示全部楼层
int n;
char p[10];
sprintf(p,"%d",n);
puts(p);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2025-5-15 18:45

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表