Tuesday 15 February 2011

How to generate Fibonacci series in C -


I want to generate Fibonacci series in C. My code is giving a compilation error. Here's the code, in fact I'm starting programming.

  main () {int n, first = 0, second = 1, next, c; Printf ("Enter the number of words \ n"); Scanf ("% d", & amp; n); Printf ("The conditions of the first% D Fibonacci series are: - \ n", n); For (c = 0; c & lt; n; c ++) {if (c & lt; = 1) next = c; Else {next = first + second; First = second; Second = next; } Printf ("% d \ n", next); }}    

This works well.

  Add # & lt; Stdio.h & gt; Int main () {int n, first = 0, second = 1, next, c; Printf ("Enter the number of words \ n"); Scanf ("% d", & amp; n); Printf ("The conditions of the first% D Fibonacci series are: - \ n", n); For (c = 0; c & lt; n; c ++) {if (c & lt; = 1) next = c; Else {next = first + second; First = second; Second = next; } Printf ("% d \ n", next); } Return 0; }    

No comments:

Post a Comment