题目内容

/*有一分数序列: 2 / 1 3 / 2 5 / 3 8 / 5 13 / 8 21 / 13......求出这个数列的前N项之和,保留两位小数。请填上合适的表达式, 使程序正确完整。//提示:当前项分子等于前项分子和分母之和;当前项分母等于前项分子;*/#includeusing namespace std;#include int main(){float n, a = 2, b = 1, s = 0;cin >> n;for (int i = 0; i <; i++) /*【1】*/{s = s + a / b;a =;/*【2】*/b = a - b;}cout << setiosflags(ios::fixed) << setprecision(2);cout << s << endl;}

查看答案
更多问题

//下面程序的输出是【1】__________。#include using namespace std;int main(){int num = 0;while (num <= 2){num++;cout << num << " ";}cout << endl;return 0;}

//下列程序运行的结果是【1】__________。#includeintmain(){intt=1,i=5;for(;i>=2;i--)t*=i;printf("%d\n",t);return0;}

//下列程序运行的结果是【1】__________。#includeintmain(){inti;for(i=1;i<=5;i++){if(i%2)printf("*");elseprintf("#");}printf("$\n");return0;}

//下列程序的输出结果是【1】__________。#includeintmain(){intn=2,k=0;while(k++&&n++>2);printf("%d,%d\n",k,n);return0;}

答案查题题库