Friday, January 22, 2016

A program to calculate ten Fibonacci Series

Object: - Write a program and algorithm to calculate ten Fibonacci Series.

 

Algorithm-
Step (1):- Start
Step (2):- Declare the variable a, b, c, i as integer type
Step (3):- initializing
Step (4):- “Enter the number of terms:”
Step (5):- Read the value of n
Step (6):- Write “series are =”
Step (7):- Read the value of a & b
Step (8):- for( i=1; i<n-2; i++)
(8.1) c ←a+b
(8.2) Write the value of c
(8.3) a←b
(8.4) b←c
(8.5) end for loop

Step (9):- stop

Program:-
# include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,n,i;
clrscr();
a=1;
b=2;
printf("Enter the number of terms:");
scanf("%d",&n);
printf("Series are:");
printf("%d\t%d\t",a,b);
for(i=1; i<n-2; i++)
{
c=a+b;
printf("%d\t",c);
a=b;
b=c;
}
getch();
}
---------------------------------------------------------------------------------

Output:-

Enter the number of terms:10
Series are:1    2       3       5       8       13      21      34      55

0 Comments:

Post a Comment