7 条题解
-
1240216cj顾皓轩 LV 4 @ 2024-04-12 15:35:26
#include <iostream>
using namespace std;
int main()
{
int a,b,c,sum=0,d;
a=1; b=1;
cin>>d;
sum=a+b;
for(int i=3; i<=d; i++)
{c=a+b; sum=sum+c;
a=b; b=c;
}
cout<<sum<<endl;
return 0;
} -
12021-01-22 22:01:39@
include <iostream>
using namespace std;
int main()
{
int a,b,c,sum,d;
a=1; b=1;
cin>>d;
sum=a+b;
for(int i=3; i<=d; i++)
{
c=a+b; sum=sum+c;
a=b; b=c;
}
cout<<sum<<endl;
return 0;
} -
12019-10-19 21:32:46@
直接通过变量迭代实现……
#include<stdio.h> int main() { int a=0,b=1; int sum=0; int i; int n; scanf("%d",&n); for(i=0;i<n;i++) { sum+=b; b+=a; a=b-a; } printf("%d",sum); return 0; }
-
12019-10-05 02:10:45@
#include <iostream> using namespace std; int num=0; //存储总和 int FLine(int n); int FLine(int n) { int x; if(n==1 || n==2) x=1; else x=FLine(n-1)+FLine(n-2); return x; } int main() { int n; cin>>n; for(int i=1;i<=n;i++) num+=FLine(i); cout<<num; return 0; }
-
02022-09-30 11:32:58@
#include <stdio.h>
//斐波拉契 i hate you!
int main() {
int a = 1, b = 1, c;
unsigned int n;
scanf("%ld", &n);
unsigned int sum = 2;
if (n == 1)
printf("1");
if (n == 2)
printf("2");
if (n > 2) {
for (int i = 3; i <= n; i++) {
c = a + b;
sum+=c;
a = b;
b = c;
}
printf("%ld", sum);
}return 0;
} -
-12021-01-25 16:03:11@
#include <iostream>
using namespace std;
int main()
{
int a,b,c,xs,x=2,m=1,d;
cin>>d;a=1;
b=1;while(m<=d-2)
{
c=a;
a=b;
b=a+c;
m++;xs=b;
x=x+xs;
}cout<<x;
return 0;
} -
-12019-10-18 13:45:38@
#include<iostream> using namespace std; int fib(int n) { int x=0; if(n==1 || n==2) x=1; else x=fib(n-2)+fib(n-1); return x; }; int main() { int sum=0; int n; cin>>n; for(int i=1;i<=n;i++) { sum=sum+fib(i); } cout<<sum<<endl; system("pause"); return 0; }
- 1
信息
- 难度
- 5
- 分类
- (无)
- 标签
- 递交数
- 2151
- 已通过
- 743
- 通过率
- 35%
- 被复制
- 8
- 上传者