Sol6hw1c
Write a program which will declare a 20-element array named terms and it will put in it the first 20 terms of the sequence ……… 1, 2, 5, 13, 34, 89,……….
ANSWER:
#include <iostream.h>
#include <iomanip.h>
main()
{
float terms[21];
int k;
terms[1] = 1;
terms[2] = 2;
for(k = 3; k <= 20; k++)
{ terms[k] = 3 * terms [k - 1] - terms [k - 2];
}
cout << setiosflags(ios::fixed)<< setprecision (5);
for(k = 1; k <= 20; k++)
cout << setw(15) << terms[k] << endl;
char hold;
cout << " \n\n enter c to continue" ;
cin >> hold;
}
The output:
1.00000
2.00000
5.00000
13.00000
34.00000
89.00000
233.00000
610.00000
1597.00000
4181.00000
10946.00000
28657.00000
75025.00000
196418.00000
514229.00000
1346269.00000
3524578.00000
9227465.00000
24157816.00000
63245984.00000
enter c to continue