刚刚学C语言,这道题我编了好久,觉得应该是对的,但是显示出来却不是
#include<stdio.h>int main()
{
int k1,k2,k3,k4,k5,k6,k7,k8,k9;
int a,b,c,d;
for(a=2;a<=1000;a++);
{b=0;
d=a;
for(c=1;c<a;c++);
if(a%c==0)
{b++;
d=d-c;
switch(b)
{case 1:
k1=c; break;
case 2:
k2=c;break;
case 3:
k3=c;break;
case 4:
k4=c;break;
case 5:
k5=c;break;
case 6:
k6=c;break;
case 7:
k7=c;break;
case 8:
k8=c;break;
case 9:
k9=c;break;
}
}
if(d==0)
{
printf("%d,it's factors are",a);
if(b>1) printf("%d",k1,k2);
if(b>2) printf("%d",k3);
if(b>3) printf("%d",k4);
if(b>4) printf("%d",k5);
if(b>5) printf("%d",k6);
if(b>6) printf("%d",k7);
if(b>7) printf("%d",k8);
if(b>8) printf("%d",k9);
printf("/n");
}
}
return 0;
}
本来想显示 6 It's factors are 1,2,3
28 It's factors are 1,2,4,7,14
496 It's factors are 1,2,4,8,16,31,62,124,248
结合却显示出来1001 It's factors are
就想请教下。
这是为什么,