The numbers in the sequence
1 1 2 3 5 8 13 21 ........
are called Fibonacci numbers. Write a program using a do....while loop to calculate and print the first m Fibonacci numbers.
(Hint: After the first two numbers in the series, each number is the sum of the two preceding numbers.)
#include <stdio.h>
void main()
{
int total,a=1,b=0,i=0,n;
clrscr();
printf("Enter the value of term:");
scanf("%d",&n);
do
{
total=a+b;
a=b;
b=total;
printf("%d ",total);
}
while(++i <n);
getch();
}
1 1 2 3 5 8 13 21 ........
are called Fibonacci numbers. Write a program using a do....while loop to calculate and print the first m Fibonacci numbers.
(Hint: After the first two numbers in the series, each number is the sum of the two preceding numbers.)
#include <stdio.h>
void main()
{
int total,a=1,b=0,i=0,n;
clrscr();
printf("Enter the value of term:");
scanf("%d",&n);
do
{
total=a+b;
a=b;
b=total;
printf("%d ",total);
}
while(++i
getch();
}
No comments:
Post a Comment