输出指定数量的斐波那契数列(用switch)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/munan2017/article/details/80316462

输出指定数量的斐波那契数列(当数值大时会溢出)

#include<stdio.h>

int ff(int number)

{

  intfirst=1,second=1,tem,i;

 printf("%d\t%d\t",first,second);

 for(i=0;i<number-2;i++)

  {

           tem=second;

           second=first+second;

           first=tem;

           printf("%d\t",second);

  }

 return 0;

}

int main()

{

   int number;

         scanf("%d",&number);

switch(number)

{

   case 1:

                   printf("1\t");

                   break;

   case 2:

                   printf("1\t1\t");

                   break;

   default:

                   ff(number);

                   //break;

        

}

         return0;

}


猜你喜欢

转载自blog.csdn.net/munan2017/article/details/80316462