关于分解质因数的问题(已经基本上完成,但判断会过多,找高手修改)
本人初学C语言,自己编了一个分解质因数的问题。代码已经达到了目标,但是由于编程上的缺陷,造成会多出几个错误的答案出来。原本准备用GOTO从判断中出来,但实在有其他原因,所以不能用GOTO。望高手指点一下,把判断或其他地方修改一下,使他多出来的错误答案消失,在这里谢谢了,如果哪里编得很幼稚,实在是刚刚开始学,请原谅!谢谢!!!(代码如下)
#include <stdio.h> #include <math.h> void fenjie(int x) { ````int y=0,a=0,b=0; ````if(x>2) ````{ ``````y=x; ``````for(a=2;a<=floor(sqrt(x));a++) ``````{ ````````if(x%a==0) ````````{ ``````````printf("%d ",a); ``````````b=b+1; ``````````y=y/a; ``````````fenjie(y); ````````} ``````} ``````if(b==0) ``````{ ````````printf("%d\n",x); ``````} ````} ````else ````{ ``````printf("2\n"); ````} } main() { ``int m; ``while(m!=0) ``{ ````scanf("%d",&m); ````fenjie(m); ``} }