Write a program to generate the first 'n' terms of the following series 0.5, 1.5, 4.5, 13.5, ...
Answers
Answered by
1
Answer:
#include
int main()
{
int b=2, ans=0, n, i=1, s=1;
printf("Enter number of terms\n");
scanf ("%d",&n);
printf("\n The series is: \n");
do
{
printf("%d \t",s);
ans = ans+s;
s = s+b;
b = b+1;
i = i + 1;
} while (i<=n);
printf ("\n The sum of the series is %d", ans);
return 0;
}
Answered by
0
C++ program to generate first 'n' terms of the series 0.5, 1.5, 4.5, 13.5,...
#include <iostream>
#include <cmath>
int main()
{
int n;
std::cin>>n;
double r=0.5;
for(int i=0;i<n;i++)
{
if(i==0)
{
std::cout<<r;
continue;
}
else
{
double t=pow(3,i-1);
double x=t+r;
r=x;
std::cout<<" "<<x;
}
}
}
- In the above program some header files and included and for loop has been used with the suitable condition.
- The output of the co-de will be the series 0.5, 1.5, 4.5, 13.5, up to the number of terms entered by the user.
Similar questions