اكتب برنامج بلغة C لعرض أول عدد n من سلسلة فيبوناتشي

  • برمجة
  • برمجة سي c

اكتب برنامج بلغة C لعرض عدد n من سلسلة فيبوناتشي

سلسلة فيبوناتشي 0 1 2 3 5 8 13 .....

الخرج المتوقع :

Input number of terms to  display : 10
Here is the Fibonacci series upto  to 10 terms :
    0     1    1    2    3    5    8   13   21   34

 

الأجوبة

/*Write a program in C to display the first n terms of Fibonacci series. Go to the editor
Fibonacci series 0 1 2 3 5 8 13 .....
*/


#include <stdio.h>

void main()
{
   int prv=0,pre=1,trm,i,n;
   printf("Input number of terms to  display : ");
   scanf("%d",&n);
   printf("Here is the Fibonacci series upto  to %d terms : \n",n);
   printf("% 5d % 5d", prv,pre);
 
  for(i=3;i<=n;i++)
   {
     trm=prv+pre;
     printf("% 5d",trm);
     prv=pre;
     pre=trm;
   }
   printf("\n");
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...