Write a program in the C programming language to print Fibonacci series up to the inputted number by using for loop statement. Below is the solution of the C program –
/* C program to print the fibonacci series*/ #include<stdio.h> main() { int f1,i,f2,f3,n; f1=0; f2=1; printf("upto which no.you want series"); scanf("%d",&n); printf("%d \t %d \t",f1,f2); for(i=2;i<n;i++) { f3=f1+f2; f1=f2; f2=f3; printf("%d\t",f3); } getch(); }
Description – For loop is used to print the series up to n. First two terms of the Fibonacci series are initialized in the compile time initialization and from the first two terms the rest of the terms are created. After creating the new term ‘ f3 ‘; it is printed. The value of the new term and it’s previous term is stored in ‘ f2 ‘ and ‘ f1 ‘ so that the next new term can be created from these variables.
Input – 12
Output – 0 1 1 2 3 5 8 13 21 34 55 89
thanks
Nice and want some typical program
2 décembre 2011Je trouve ça très chiant d’avoir un ajout automatique des groupes, j’ai plus de 1000 &lbp;ou&nasq;amis » et tous les jours j’ai le droit à un groupe de plus, du plus farfelu au plus inutile. Personnellement ça me gonfle !