求fibonacci数列的前12项的C语言代码
时间: 2024-02-22 10:57:23 浏览: 112
C语言程序设计-用函数求fibonacci数列前n项的和;说明:fibonacci数列为数列的第一项值为1,第二项
5星 · 资源好评率100%
以下是求Fibonacci数列前12项的C语言代码:
```c
#include <stdio.h>
int main() {
int n1 = 0, n2 = 1, nextTerm, i;
printf("Fibonacci Series: ");
for (i = 1; i <= 12; ++i) {
printf("%d, ", n1);
nextTerm = n1 + n2;
n1 = n2;
n2 = nextTerm;
}
return 0;
}
```
输出结果如下:
```
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,
```
阅读全文