How do I do this with C? Fibonnacci Sequence -


perhaps me out this.

  • using concept of cycle generate fibonacci series until reaching 10000 or little more that.

so have code , it's supossed work , show me want doesn't. can tell me what's wrong it? opens doesn't work @_@

#include <stdio.h> #include <stdlib.h>   int main() {     int i=0,j=0,sum=1,num;      while(sum>=1000){     {        printf("%d\n",sum);         i=j;         j=sum;         sum=i+j;           }    system("pause");   } 

the code made calculating fibonacci sequence following:

#include <stdio.h> #include <stdlib.h>  int main() {     int i=0,j=0,sum=1,num;     printf("introduce limit fibonacci sequence: ");     scanf("%d",&num);     while(sum<num)     {        printf("%d\n",sum);         i=j;         j=sum;         sum=i+j;                    }      system("pause");   } 

in first snippet, have typo

while(sum>=1000){ 

should be

while (sum < 10000){ 

i said 'less than' rather 'less or equal to' because of wording of assignment.

you want print out fn fn first such number > 10000. since j fn-1 change while loop condition

while (j <= 10000) { 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -