Monday, 27 February 2012

Fibonacci series programme in C

/*print fibonacci series*/
//programme will run in linux change header file for turbo c

//In mathamatics, the Fibonacci numbers are the numbers in the following integer sequense:
0,\;1,\;1,\;2,\;3,\;5,\;8,\;13,\;21,\;34,\;55,\;89,\;144,\; \ldots\;
F_n = F_{n-1} + F_{n-2},\!\,

//programme start from here


#include<stdio.h

void main() 
  { 
     int Term,i,val3,val1=0,val2=1; 
     printf("Enter the value for Fibonacci series of nth term := "); 
     scanf("%d",&Term); 
     printf("%d %d ",val1,val2); 
   

 for(i=0;i<=Term;i++)   //logic for fibonacci series
       { 
         val3=val1+val2;   
         val1=val2; 
         val2=val3; 
         printf("%d ",val3); 
      } 
 

No comments:

Post a Comment

Compiler for C,C++ and Python {paste your programme to see the output}