Fibonacci

  • File name: Fibonacci
  • Size: 187 b
yes /

Download

In the Fibonacci sequence (1,2, ...) each term is the sum of the previous two and the first two values are 1.

The code displays the terms of 10 to 20 included.


#include <stdio.h>

 

int main(){
int i=3, penult=1, ult=1, m;
while(i<=20){
    m=penult+ult;
    ult=penult;
    penult=m;
    if(i>=10)printf("%d ",m);
    i++;
}
return 0;
}

 

More exercises in https://www.youtube.com/channel/UCK05KbyByXPCMRJEqyL4VXw/videos

No ratings yet - be the first to rate this.

Add a comment