cp_1_lect_30 - Problem : Generating Fibonacci Numbers...

This preview shows pages 1–6. Sign up to view the full content.

5/10/10 11 Problem : Generating Fibonacci Numbers Definition: The sequence of Fibonacci numbers is defined recursively f0 = 0, f1 = 1, fi+1 = fi + fi-1 for i = 1, 2, 3, ………. So the sequence is like 0, 1, 1, 2, 3, 5, 8, 13, 21, ……

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
5/10/10 22 Algor ithm Development Let f1 contains the value of the current fibonacci number and f0 contains the value of the previous Fibonacci number. Save the value of f1 in a
5/10/10 33 Program to print first 10 Fibonacci Numbers #include<stdio.h> #define STEP 10 main() /* To generate Fibonacci Numbers/ { int f0 = 0,f1 = 1, i, temp; printf(“%d, %d, ”,f0,f1); /* Loop */ for(i = 0; i<STEP; i++) { temp = f1; f1 += f0;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
5/10/10 44 Exercise: Rewrite the Fibonacci series program to print the series till the Fibonacci number fnum. User will enter the value of fnum. Assume that fnum is a valid Fibonacci number Example: fnum = 377 Sol: Hint : Set the appropriate condition in for
5/10/10 Example2 1. Set line to 1 2. Loop (line not greater than limit) 1. Set num to 1 2. Loop (num !> line) 1. Print num 2. Increment num 3. End loop 4. Advance line 5. Increment line 3. End loop Algorithm to print a series of numbers in the form of a right triangle 1 12 123 #include <stdio.h> int main() { int limit; printf (“Enter a no between 1 and 9:”); scanf (“%d”, &limit);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/07/2010 for the course CS&IS TA C162 taught by Professor Kavitha during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 19

cp_1_lect_30 - Problem : Generating Fibonacci Numbers...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online