WAP to display 'n' Fibonacci numbers.(do while loop)

//Fibonacci numbers to nth terms

#include<stdio.h>
#include<conio.h>
void main()
{        clrscr();
 int a=0,n, b=1,c,count=0;
  printf("enter the n th term:");
  scanf("%d",&n);
  printf("fibonacci numbers to %d term is :\n",n);
  printf("%d\n",a);
  printf("%d\n",b);
count=2;     // first two Fibonacci numbers is used .
 do
{
  c=a+b;
 printf("%d\n",c);
 a=b;
 b=c;
count++; 
 }
 while(count<=n);
getch();

}
output:
enter the n th term:10
fibonacci number to 10 term is:
0
1
1
2
3
5
8
13
21
34


SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment