我为阶乘分解制作了一个 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;    
}
我能做些什么来解决这个问题?