各位电脑高手,关于C语言的问题想请教各位:用递归法将一个正整数n的各个数字分别输出。麻烦各位啦,谢谢

如题所述

楼上的兄弟
你的程序有问题吧
你的递归出口设置错了 不会有数输出
还有用你的算法
如果n=1200
你输出的也是0 0 2 1
可是好像应该输出1 2 0 0才对啊

#include<stdio.h>
#include<math.h>

void out(int n,int i)
{
int x,y,j;
y=int(pow(10,i));
if (n!=0)
{
x=n/y;
n=n-x*y;
printf("%d ",x);
}
else printf("0 ");
i--;
if(i>=0) out(n,i);
}

void main()
{
int n,x,y,i;
printf("输入要处理的数字:");
scanf("%d",&n);
x=n;
i=-1;

while(x!=0)
{
x=x/10;
i++;
}
printf("\n\n");
printf("输出处理后的数字:");
out(n,i);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-05-05
#include<stdio.h>
int f(num){
int x;
if(num==0)
return 0;
else{
x=num%10;
f(num/10);
}
printf("%d ",x);
return 0;
}
void main(){
int num;
printf("Please input the number:");
scanf("%d",&num);
f(num);
printf("\n");
system("pause");
}

希望可以帮到你喇!o(∩_∩)o...
第2个回答  2008-05-05
恩,不错不错
第3个回答  2008-05-05
#include <stdio.h>
#include <conio.h>
#include <math.h>
int outInt(int);
extern float pow10(float x);
int main()
{
int i,x;
printf("输入一个整数:");
scanf("%d",&x);
int n = (int)log10(x) + 1;
printf("输出结果:");
for(i=n-1;i>=0;i--)
printf("%d ",outInt(x/(int)pow(10,i)));
getch();
return 0;
}
int outInt(int ia)
{
int a;
a=ia%10;
return a;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网