write the code on C++ . Project 2: Fibonacci-like Sequences [SEQ] Textbook Secti
ID: 3806000 • Letter: W
Question
write the code on C++ .
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.