This is a simple Program in C language you can Generate
Fibonacci Series From
this Program I have made this program Using While Loop Scratch your mind & you can also try it with For & do while loop. Fibonacci series starts with 0 & 1 & precede with the addition of last two terms ie net term will be 0+1 i.e. 1 & next 1+1=2 Then next 2+1=3 so series becomes 0,1,1,2,3,5,8,13,21,34,65……so on
/* Program to Create a Fibonacci Series */
/* Author Mitochondria Technologies Inc. */
#include<stdio.h>
#include<conio.h> /*Header Files */
void main() /*Main function to begin program & it is kept empty*/
{
int a,b,c,count=0,n; /*variable declaration & also initialization counter in one statement*/
clrscr(); /*clear screen to clear outputs after usage*/
printf("Enter The Value of No. : "); /*Input command for user for length of series*/
scanf("%d",&n); /*Taking input*/
a=0,b=1;
printf("%d\n",a);
printf("%d\n",b);
while(count<n-2) /*condition counter*/
{
c=a+b; /*series generating logic*/
printf("%d\n",c);
a=b;
b=c;
count++; /*increment counter*/
}
getch(); /*getch function to retain output on screen*/
}
No comments:
Post a Comment