Write a c++ program to generate the first 'n' terms of the following series 0.5, 1.5, 4.5, 13.5, ...
Answers
Following are the program in the c++ Programming language
Explanation:
#include <iostream> // header file
#include <cmath> // header file
using namespace std; // namespace
int main()
{
int n1,k=0; // variable declaration
double r1=0.5; // variable declaration
double sum,x1; // variable declaration
cout<<"Enter the terms:";
cin>>n1; // Read the number by user
while(k<n1) // iterating the loop
{
if(k==0) // check the condition
{
cout<<r1; // display
continue;
}
else
{
sum=pow(3,k-1); //power
x1=sum+r1;
r1=x1;
cout<<" "<<x1; // display
}
k++;
}
}
Output:
Enter the terms:4
0.5, 1.5, 4.5, 13.5
Following are the description of the program
- Read the value of terms by the user in the "n1 " variable .
- Iterating the while loop for printing the series .
- The pow is used for printing the power .
- Finally print the series .
Learn More :
- brainly.in/question/16711846
Answer:
#include<iostream>
using namespace std;
int main()
{
int n,i;
float x=0.5;
cin>>n;
while(i<n){
cout<<x<<" ";
x=(x*3);
i++;
}
}
Explanation:
cndtn is x=x*3