mdsk.net
当前位置:首页 >> 斐波那契数列 For >>

斐波那契数列 For

a3=a1+a2; a1=a2; a2=a3 迭代就行了啊

public class Fibonaci{ public static void main(String[] args){ long[] fibonaci=new long[20]; fibonaci[0]=1; fibonaci[1]=1; for(int i=2;i

#include #include int main() { int i = 0; int limit = 10; // 输出前10个fibonacci数 int pre1 = 1; // 当前计算值前面第二个fibonacci数 int pre2 = 1; // 当前计算值前面一个fibonacci数 int res; // 当前计算值 for (i; i < limit; i++) {...

#include int main() { long fib[41] = {0,1}; int i; for(i=2;i

#include int main() { int n,i=1; double a=1,b=1; scanf("%d",&n); if(n==1) printf("1"); else if(n==2) printf("1 1"); else { printf("1 1"); for(i=3;i

a = 0; b = 1; for i = 1:1000 c = a+b; a = b; b = c; if a < 10000&&b > 10000 break; end end result_max = a

public class Fibonaci{ public static void main(String[] args){ long[] fibonaci=new long[20]; fibonaci[0]=1; fibonaci[1]=1; for(int i=2;i

public static void main(String[] args) { int a = 1; aaa(20,a,a,1); } public static void aaa(int max,int one,int two,Integer index) { if(index>=21) return; if(index%5==0) System.out.println(one+two); else System.out.print(one+tw...

#include void main(){int f1=1,f2=1,fn;int i,n;printf("input n: ");scanf("%d", &n );if ( n>=1 )printf("1");if ( n>=2 )printf(" 1");for( i=2;i

C语言,用for循环,求Fibonacci数列前40个数的程序如下:#include int main(void){ int a=1,b=1,t=0; printf("%d,",a); printf("%d,",b); for(int i=0;i

网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com