遞迴_階層運算

 avatar
user_3763047219
c_cpp
2 years ago
311 B
0
Indexable
Never
int fac(int n);


int fac(int n) {
    while (n > 0) {
        if (n == 1) {
            return 1;
        }
        else {
            return n * fac(n - 1);
        }
    }
}

#include <stdio.h>


int main() {

    int n;
    scanf("%d", &n);
    printf("%d", fac(n));
    return 0;

}