(C++) CPP Programs - 4

Friday, December 14, 2007

4. Write a C program to generate first ‘N’ Fibonacci numbers.

/* Fibonacci Series*/

#include

#include

void main()

{

int i,n,f1=0,f2=1,f;

clrscr();

printf("Enter the value for n\n\a");

scanf("%d",&n);

printf("%d\t%d",f1,f2);

for(i=3;i<=n;i++)

{

f=f1+f2;

printf("\t%d",f);

f1=f2; //exchanging

f=f2;

}

printf("Sum of Fibonacci numbers=%d\n\a",f);

getch();

}

0 comments:

Post a Comment

Chitika

About This Blog

Followers

Blog Archive

  © Blogger template The Professional Template II by Ourblogtemplates.com 2009

Back to TOP