C program to print N FIBONACCI numbers

/*Write a C program to generate and print first N FIBONACCI numbers*/ #include <stdio.h> void main() {   int   fib1=0, fib2=1, ...


/*Write a C program to generate and print first N FIBONACCI numbers*/

#include <stdio.h>

void main()
{
  int   fib1=0, fib2=1, fib3, N, count=0;

  printf("Enter the value of N\n");
  scanf("%d", &N);

  printf("First %d FIBONACCI numbers are ...\n", N);
  printf("%d\n",fib1);
  printf("%d\n",fib2);
  count = 2;           /* fib1 and fib2 are already used */

  while( count < N)
  {
    fib3 = fib1 + fib2;
    count ++;
    printf("%d\n",fib3);
    fib1 = fib2;
    fib2 = fib3;
  }
} /* End of main() */

/*--------------------------
Enter the value of N
10
First 5 FIBONACCI numbers are ...
0
1
1
2
3
5
8
13
21
34
-------------------------------*/

Related

C TUTORIAL 6972940538380150775

Post a Comment

emo-but-icon

Search Here

Popular query

Follow Us

Ads By Google

Get free Update

Enter your email address:

E-mail verification is must for complete subscription

Delivered by FeedBurner

Circle AFS on Google Plus!

Follow AFS Google+ page
 

Side Ads

DMCA protected
Information, images and the content on this blog is Copyright ©AFS2011-2018. Please do not copy Any content for commercial purpose else we have to take a legal action. Thanks !!

Total Pageviews

Recent

free counters
 

Connect Us

Speech by ReadSpeaker

item