Problem R: 求斐波那契数列的前n项值

#include<stdio.h>
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF){
    int x1,x2,i,x;
    x1=1;
    x2=1;
    if(n==1)
    printf("1");
    if(n==2)
    printf("1 1");
    if(n>2)
    {
    printf("%d %d",x1,x2);
    for(i=3;i<=n;i++)
    {
        x=x1+x2;
        printf(" %d",x);
        x1=x2;
        x2=x;
    }}
    printf("\n");
    }
    return 0;
}

 

posted @ 2018-10-28 12:53  MichaelCecil  阅读(2011)  评论(0编辑  收藏  举报