社区
C语言
帖子详情
一道题,递归的,不知什么意思
skywgs
2005-03-18 10:35:51
编写一个递归函数,将输入的整数转换成字符串输出到屏幕上,要求不能用C编译器提供的sprintf,另外,编写主函数调用该函数,以验证其正确性。
是不是原样输出呀
哪位高手编个代码
...全文
103
4
打赏
收藏
一道题,递归的,不知什么意思
编写一个递归函数,将输入的整数转换成字符串输出到屏幕上,要求不能用C编译器提供的sprintf,另外,编写主函数调用该函数,以验证其正确性。 是不是原样输出呀 哪位高手编个代码
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
sooler
2005-03-18
打赏
举报
回复
#include <cstdio>
#define N 20
int convert (int n, char *a);
int main()
{
int n;
char a[N];
scanf("%d", &n);
printf("Int: %d\n", n);
convert (n, a);
printf("String: %s\n", a);
return 0;
}
int convert (int n, char *a)
{
int i, j;
char temp[N];
i = 0;
while (n)
{
temp[i] = n%10 + '0';
n /= 10;
i++;
}
temp[i] = '\0';
for(j=0; j < i; j++)
a[j] = temp[i-j-1];
a[i] = '\0';
return 0;
}
skywgs
2005-03-18
打赏
举报
回复
steedhorse(晨星) ,多谢了
晨星
2005-03-18
打赏
举报
回复
你给的分数太少,所以俺的程序也只能处理正整数。:P
你把它改一改,让它也能处理0和负数吧。:)
晨星
2005-03-18
打赏
举报
回复
#include <stdio.h>
void PrintNum(int n);
int main()
{
PrintNum(12345);
return 0;
}
void PrintNum(int n)
{
if(0 == n)
return;
else
{
PrintNum(n / 10);
printf("%d", n % 10);
}
}
IBM Minus One
You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn. The crew is put into stasi
hdu1328——IBM Minus One
原
题
: Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn.
C语言
70,038
社区成员
243,247
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章