Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write the code on C++ . Project 2: Fibonacci-like Sequences [SEQ] Textbook Secti

ID: 3806000 • Letter: W

Question


write the code on C++ .

Project 2: Fibonacci-like Sequences [SEQ] Textbook Section: 4.23 z initial conditions Directions: Given a degree 2 recurrence relation an can-1 +dan and two ao and ar, where 4d 20. find the closed (explicit) formula for the sequence. (Hint: you will need to consider two cases: real and repeated roots. Input: c, d, ag, and (where c 4d 20) Output: the closed form expression Extra Credit: Add a feature to be able to calculate an for n given n Add a feature to be able to start at any index i ie: given ai 2 and an 1) Due Date: March 17 Revision Due Date: April 21 Project 3: The Greatest Common Divisor UGCD Textbook Section: 7.36 Directions: Implement the Euclidean Algorithm to compute the greatest common divisor of any two integers. These two numbers should be able to be positive, negative, zero, or any combination thereof. (Hint: be carefull when dealing with zero and negative numbers. Input: 2 integers Output: 1 integer (ie: the god of the given integers) Extra Credit: Find the linear combination of the 2 given integers which sums to their god. Due Date: April 1A Revision Due Date: May 1

Explanation / Answer

1) /*FibonacciLikeSequence.CPP */

#include<iostream>
using namespace std;
int main()
{
   int c,d,a0,a1,an;
   int range = 10;
   cout<<"Enter c,d,a0 and a1 Values:"<<endl;
   cin>>c>>d>>a0>>a1;
   cout<<" Series: "<<a0<<endl<<a1<<endl;
   for(int i=0;i<range;i++){
       an = c*a0 + d*a1;
       a0 = a1;
       a1 = an;
       cout<<an<<endl;
   }
   return 0;
}

/*Sample Input and Output */

Enter c,d,a0 and a1 Values:
4 5 2 3

Series:
2
3
23
127
727
4143
23623
134687
767927
4378383
24963623
142331647


2) /*GreatestCommonDivisor.CPP */

#include<iostream>
using namespace std;
int gcd(int,int);
int main()
{
   int num1,num2,result;
   cout<<"Enter two numbers:";
   cin>>num1>>num2;
   result = gcd(num1,num2);
   cout<<"Greatest Common Divisor (GCD) of "<<num1<<" and "<<num2<<" is:"<<result;
}
int gcd(int a,int b){
   if( a%b == 0)
       return b;
   return gcd(b,a%b);
}

/*Sample Input and Output */

Run1:
_____

Enter two numbers:257184 800128
Greatest Common Divisor (GCD) of 257184 and 800128 is:28576

Run2:
______

Enter two numbers:268 36
Greatest Common Divisor (GCD) of 268 and 36 is:4