We all know fibbonacci sequence (for eg 1,1,2,3,5,8,13,.... sequence in which next no is addition of previous 2 fibonacci numbers) so we will try to write algorithm to generate fibbonacci sequence .
F1=1st number, F2=2nd number -->F3=f1+f2=1+2=3 F4=f2+f3=2+3=5 F5=f3+f4=3+5=8, and so on. f1 f2 f3 f4 f5 f6 f7.............. 1 2 3 5 8 13 21.............
In algorithm:
1. Assign sum=0, A=0, B=1, i=1
2. Get the no. of terms upto which u want to generate the Fibonacci no, i.e., n.
3.Add A and B to get the next Fibonacci number
4. Assign the value of B to A i.e. A=B
5. Assign the value of sum to B i.e. B=sum
6. Write the value of su to get next Fibonacci number in the series.
7. increment i with 1 i.e. i=i+1 and repeat step 3,4,5,6 with the last value of i=n(n is the no. of terms which u wnt to generate Fibonacci no. series.)
8. Stop
F1=1st number, F2=2nd number -->F3=f1+f2=1+2=3 F4=f2+f3=2+3=5 F5=f3+f4=3+5=8, and so on. f1 f2 f3 f4 f5 f6 f7.............. 1 2 3 5 8 13 21.............
In algorithm:
1. Assign sum=0, A=0, B=1, i=1
2. Get the no. of terms upto which u want to generate the Fibonacci no, i.e., n.
3.Add A and B to get the next Fibonacci number
4. Assign the value of B to A i.e. A=B
5. Assign the value of sum to B i.e. B=sum
6. Write the value of su to get next Fibonacci number in the series.
7. increment i with 1 i.e. i=i+1 and repeat step 3,4,5,6 with the last value of i=n(n is the no. of terms which u wnt to generate Fibonacci no. series.)
8. Stop
This is prof that diagrams can be useful when it comes to programming. Specially flowcharts are the best way to plan a programs flow
ReplyDeleteGreat article....u can find the program at: Fibonacci series program
ReplyDeletewhere is program
ReplyDeleteA Computer Science portal for geeks. It contains well written, well thought and well
ReplyDeleteexplained computer science and programming articles, quizzes and practice/competitive
programming/company interview Questions.
website: geeksforgeeks.org
A Computer Science portal for geeks. It contains well written, well thought and well
ReplyDeleteexplained computer science and programming articles, quizzes and practice/competitive
programming/company interview Questions.
website: geeksforgeeks.org