ccplusplus.com
Learn C, C++ Concepts
Friday, October 7, 2011
fibonacci series in c
/************************************************************* * File : print-fibonacci-numbers.c * Author : Saurabh Gupta * Desc : c program for fibonacci series * c program to print fibonacci series * Source : http://saurabhgupta0527.blogspot.com/p/c.html * Created : AM 09:20 10 October 2011 ************************************************************/ #include<stdio.h> int main() { int nFirstFibTerm=1, nSecondFibTerm=1, nNextFibTerm=0, nFibNumber, nCounter=0; printf("Enter Number : "); scanf("%d", &nFibNumber); printf ("Fibonacci series of %d\n", nFibNumber); do { printf("%d\t",nFirstFibTerm); nCounter++; nNextFibTerm = nFirstFibTerm+nSecondFibTerm; nFirstFibTerm = nSecondFibTerm; nSecondFibTerm = nNextFibTerm; } while(nCounter < nFibNumber); printf("\n"); return 0; } /* * OUTPUT * [sgupta@rhel54x64 c]$ gcc print-fibonacci-numbers.c -o print-fibonacci-numbers [sgupta@rhel54x64 c]$ ./print-fibonacci-numbers Enter Number : 10 Fibonacci series of 10 0 1 1 2 3 5 8 13 21 34 [sgupta@rhel54x64 c]$ */
See also
Other popular tricky C Sample Codes and language Concept
.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment