我已經爲因子分解一個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