預先感謝您。我很欣賞任何和所有的反饋。我是編程新手,我正在開發一項基於用戶請求的數字打印斐波納契數列的任務。我已經完成了大部分代碼,但還有一件我很困難。我希望以表格格式輸出,但是我的代碼有些問題,並且我沒有在輸出中獲得所有我想要的數據。灰色是我的代碼,我的輸出和我想要的輸出。爲斐波那契序列創建表格
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, n;
int sequence = 1;
int a = 0, b = 1, c = 0;
printf("How many Fibonacci numbers would you like to print?: ");
scanf("%d",&n);
printf("\n n\t\t Fibonacci Numbers\n");
printf(" %d \t\t\t%d\n \t\t\t%d\n ", sequence, a, b);
for (i=0; i <= (n - 3); i++)
{
c = a + b;
a = b;
b = c;
sequence++;
printf("\t\t\t%d\n ", c);
}
return 0;
}
Here is my output:
How many Fibonacci numbers would you like to print?: 8
n Fibonacci Numbers
1 0
1
1
2
3
5
8
13
Here is my desired output:
How many Fibonacci numbers would you like to print?: 8
n Fibonacci Numbers
1 0
2 1
3 1
4 2
5 3
6 5
7 8
8 13
您是不是要找'的printf(「%d \ t \ t \ t%d \ n「,序列,c);'? – user3078414