Fibonacci Sequence of numbers

Fibonacci series is the sequence of numbers where each member is sum of previous two numbers. First two numbers of the series are 0 & 1. We will print first 10 numbers by using a for loop but same can be increased to any number of numbers.
#include <stdio.h>
int main(void){
int i;
int num1=0;
int num2=1;
int num3;

for ( i=1;i<=10;i++){
num3=num1+num2;
printf("%d,",num3);
num1=num2;
num2=num3;
}
return 0;
}
Output is here
1,2,3,5,8,13,21,34,55,89,
You can increase the loop by changing the upper limit of i to any value at the for loop.
After displaying the value of variable num3 we reassigned the numbers by making num1 value equal to num2 and num2 value equal to num3. Then the loop continues ...
Your Rating




Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer