简单的C程序不起作用

Col*_*een -1 c

我写了这个程序:

#include <stdio.h>

/*Part B

Write a program that:

defines an array of 10 ints
assigns factorial(x) to array element x, for x in the range 0 through 9, inclusive
copies those array elements into a second array of 10 ints, but in reverse order (i.e., element 0 is factorial(9), element 1 is factorial(8), and so on)
prints out that second array to the terminal*/

int factorial(int n){
    int factorial = 1;
    while(n>1){
        factorial = n*factorial;
    }
    return factorial;
}

int main(int argc, char **argv){
    int arr1[10];
    int arr2[10];

    int i = 0;
    for(i = 0; i<10; i++){
        printf("%d", i);
        arr1[i] = factorial(i);
    }

    for(i = 9; i>=0; i--){
        arr2[i] = arr1[9-i];
        printf("%d ", arr2[i]);
    }
    printf("\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是当我跑它时它只是坐在那里.我认为这与对factorial的调用有关,因为当我发表评论时它立即起作用,但是当它进入时,它甚至没有进入第一个printf.

我究竟做错了什么?

Nic*_*ico 6

while(n > 1){
    factorial = n*factorial;
}
Run Code Online (Sandbox Code Playgroud)

你错过了n--;