1,1,2,3,5 ,8.......在C语言中如何实现?是通过求通项公式?
来源:百度知道 编辑:UC知道 时间:2024/05/14 02:03:50
我需要的答案应该是用比较低级的方法。不用数列应该也可以解决的。下面是我的解答。
#include <stdio.h>
void main()
{
int a=1,b=1,c,i,j,max;
printf("enter your number(>2):");
scanf(%d,&max);
printf("1, 1,");
for(i=0;i<=max-2;i++)
{
c=a+b;
j=b;
a=j;
b=c;
printf("%4d",c);
}
}
#include <stdio.h>
void main()
{
int a=1,b=1,c,i,j,max;
printf("enter your number(>2):");
scanf(%d,&max);
printf("1, 1,");
for(i=0;i<=max-2;i++)
{
c=a+b;
j=b;
a=j;
b=c;
printf("%4d",c);
}
}
可以用通项求就是斐波那契数列。就用递归。
#include"stdio.h"
void main()
{
int num,i,j;
unsigned long fa[100];
fa[1]=1;
fa[2]=1;
printf("please input your need number:");
while(scanf("%d",&num)!=1)
while(getchar()!='\n');
for(i=3;i<=num;++i)
fa[i]=fa[i-1]+fa[i-2];
for(j=1;j<=num;++j)
printf("%ld ",fa[j]);
}
因为数据类型的原因可以正常显示前45项
#include <windows.h>
#include <iostream.h>
void test(INT m)
{
for (INT i=0;i<m;i++)
{
if ((i=0)||(i=1))
cout<<"1 ";
if (i>1)
cout<<"%d "<<(test(i-1)+test(i));
}
}
void main()
{
INT m=10; //你要显示多少个,这里就=多少
test (m);
return;
}
关键就在一个递归
通项公式算出来的可能不会是整数(涉及到开方运算)
用递归才是正解:F(1)=1;F(2)=1;F(n)=F(n-1)+F(n-2)
0,1,1,2,3,5,8......后面接什么?
1+2+3+4+5+6+7+8......+100000=?
1+2-3-4+5+6-7-8.........-2003-2004
1,1,1,1,1,1,1.....是1,2,3,4,5,6,7,8.....的子数列吗
0,1,1,2,3,5,8....的通项公式是什么?
1,1,2,3,5,8.......这个数列的第2005个数是多少
1,1,2,3,5 ,8.......在C语言中如何实现?是通过求通项公式?
1/2,2/3,3/5,4/8......第一百个数是多少?
1,2,3,4,5,6,7,8.....是1,2,3,4,5,6,7,8.....的子数列吗
3/2,1,5/8,3/8...... 通项公式