求任意一个数字的阶乘《C语言版》

/*
 Enter a positive integer: 3
 Factorial of 3 is: 6

 Enter a positive integer: 5
 Factorial of 5 is: 120

 Enter a positive integer: 6
 Factorial of 6 is: 720

 Enter a positive integer: 9
 Factorial of 9 is: 362880
 */

#include 

void add(int *);

int main(void)
{
    int in;
    printf("Enter a positive integer: ");
    scanf("%d", &in);
    int cmp = in;
    int * key = ∈
    add(key);
    printf("Factorial of %d is: %d\n", cmp, in);

    return 0;
}

void add(int * in)
{
    int key = *in;
    while(--key > 0)
        *in *=  key;

    return;
}


你可能感兴趣的:(C)