|
1 |
阶乘:factorial of n (n!) = 1 * 2 * 3 * 4....n |
#include <stdio.h>
int main() {
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
// shows error if the user enters a negative integer
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d = %llu", n, fact);
}
return 0;
}
结果:
|
1 2 3 4 |
Enter an integer: 25 Factorial of 25 = 7034535277573963776 Process returned 0 (0x0) execution time : 4.852 s Press any key to continue. |
除教程外,本网站大部分文章来自互联网,如果有内容冒犯到你,请联系我们删除!