遞迴_階層運算

 avatar
user_3763047219
c_cpp
3 years ago
311 B
2
Indexable
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;

}
Editor is loading...