Question: ## Code Block Look over the code below. It is written in C not C + + but it should be fairly straightforward to read

## Code Block
Look over the code below. It is written in C not C++ but it should be fairly straightforward to read if you know C++. Answer the questions below and write the code. I will refer to the for statments by the order in which they appear in the code for instance block one refers to the first for loop.
#include
int a(int a0, int d, int i)
{
return d*i + a0;
}
int recurrencea(int anminusone, int d)
{
return anminusone + d;
}
int fibb(int n)
{
if(n ==0|| n ==1){
return 1;
}
return n*fibb(n-1);
}
int main()
{
for(int i=0; i<=5; i++){
printf("%d
", i);
}
printf("
");
for(int i=0; i<=5; i++){
printf("%d
",a(17,3, i));
}
printf("
");
int a =17;
printf("%d
", a);
for(int i=0; i<5; i++){
printf("%d
", recurrencea(a,3));
a = recurrencea(a,3);
}
printf("
");
for(int i=0; i<6; i++){
printf("%d
", fibb(i));
}
return 0;
}
0
1
2
3
4
5
17
20
23
26
29
32
17
20
23
26
29
32
1
1
2
6
24
120
## Questions
1. Blocks 2 and 3 generate the same output but their `for` loops are not the same. How are the loops different and why? Could you rewrite block 3 so that the bounds of the loop are the same as in block 2?
1. Implement a `for` loop which generates and prints the 16th through 27th terms of the geometric sequence that starts at 18.25 and has a common ratio of 1.5.
1. Implement a function that uses a recurrence relation to achieve the same as above.
1. Write a short program which stores the 3rd through 99th terms of the arithmetic sequence which starts at 54321 and has a common difference of -33.2 in an array. Generate the terms using a function that implements a recurrence relation using the previous element of the array.
1. Write a short program using a recursive function that generates the terms of the sequence a_n = a_n-1* a_n-2. Generate the first twenty terms of the sequence if a_1=3 and a_2=0.5. Store the elements in an array. Print the elements in the array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!