这是我的代码,用于查找数字的阶乘并查找阶乘中所有数字的出现次数。
#include <stdio.h>
#include <stdbool.h>
int iFactorial(int iCount)
{
int iProduct = 1;
int iNumber = 1;
while (iNumber <= iCount)
{
iProduct *= iNumber;
iNumber++;
}
return iProduct;
}
int main(void)
{
int iFac[10] = {0};
int iCount = 0;
printf("Please input a Integer: ");
scanf("%d",&iCount);
iFac[iCount] = iFactorial(iCount);
printf("\nThe value of the factorial of %d is %d\n",iCount, iFac[iCount]);
int i;
int dig[10] = {0};
while (iFac <=0)
{
int n;
n= ((iFac % 10) + 1);
dig[n] = dig[n] +1;
iFac = iFac / 10;
}
for (i = 0; i > 9; i++)
{
if (dig[i+1] >0)
{
printf ("%d %d\n", i, dig[i+1]);
}
}
}
我需要找到合适的写作方法array[x] = array[x] + 1