Write a C++ program to generate the first 'n' terms of the following series 5, 16, 49, 104, 181...
Answers
Answer:
#include <iostream>
int main() {
int i,n,t;
std::cout<<" Enter number terms n";
std::cin>>n;
std::cout<<" sequence:";
for(i=1;i<=n;i++)
{
t=(11*i*i)-(22*i)+16;
std::cout<<t<<",";
}
}
Explanation:
Answer:
A C++ programme to generate the given pattern first 'n' terms has been provided.
Explanation:
Here is a C++ program to generate the first 'n' terms of the given series:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the number of terms to generate: ";
cin >> n;
int term = 5;
cout << "The first " << n << " terms of the series are: ";
for(int i=1; i<=n; i++) {
cout << term << " ";
term += (i+1)*(i+1);
}
return 0;
}
In this program, we first take the input for the number of terms to generate from the user. Then, we initialize the first term of the series to be 5. We use a for loop to generate the terms of the series by adding the square of the current term's index to the previous term. Finally, we print the generated terms of the series to the console.
For example, if the user enters '5', the program will generate the first 5 terms of the series: 5, 16, 49, 104, 181.
For more such question: https://brainly.in/question/12809215
#SPJ2