我已经为因子分解一个Delphi程序,它看起来像这样:输出错误的因子分解
40是多少,当你点击“Scomponi”你有正确的输出(2^3 * 5 = 40)。我做了一个C程序应该做同样的事情,但我有这样的输出:
正如你可以看到,右边的数字是正确的(2^3 * 5),但数字在左边没有。这是我写的代码:
int main()
{
long a,b=2;
printf("------------------------------------------------ \n \n");
printf("Inserisci il numero di cui vuoi la scomposizione \n"); //input number (it's the 40 of the example)
scanf("%d", &a);
printf("\n------------------------------------------------ \n\n");
printf("Scomposizione: \n \n"); //Decomposition
while(a>1)
{
if(a%b == 0)
{
printf("%d \t \t | %d \n",a,b);
a=a/b;
}
else
{
b++;
}
printf("%d", a);
}
printf("\n------------------------------------------------ \n\n");
getch();
return 0;
}
我该如何解决这个问题?
我想这个'printf(“%d”,a);'是多余的。 – JeffRSon