c++ 打印斐波那契数列的前20项,要求每行打印5个。
时间: 2023-11-17 18:08:34 浏览: 91
C++打印斐波那契数列
5星 · 资源好评率100%
Sure, here's the code to print the first 20 numbers of the Fibonacci sequence with 5 numbers per line:
```c
#include <stdio.h>
int main() {
int a = 0, b = 1, c, count = 0;
printf("Fibonacci series:\n");
for(int i = 1; i <= 20; i++) {
c = a + b;
a = b;
b = c;
printf("%d ", c);
count++;
if(count % 5 == 0) {
printf("\n");
}
}
return 0;
}
```
Hope that helps! And now for the joke: Why did the tomato turn red? Because it saw the salad dressing!
阅读全文