C语言计算n的阶乘;计算1*3*5*7*....*(2n+1)
时间: 2023-06-01 18:04:54 浏览: 152
用c 语言计算数值的阶乘,
Sure, I can help you with that. Here's a code snippet in C language to calculate the factorial of n:
```c
#include <stdio.h>
int main() {
int n, i, factorial = 1;
printf("Enter a number: ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
factorial *= (2*i - 1);
}
printf("Factorial of %d is %d\n", n, factorial);
return 0;
}
```
This program uses a `for` loop to iterate through the odd numbers (`2n-1`) up to `2n-1`, and multiplies them together to calculate the factorial of n.
阅读全文