Answer to Question #259034 in C++ for Charmaine

Question #259034

Write a program using iterative loop to calculate (numerically) the series:

1/x + 1/x 2 + 1/x3 + 1/x4 + . . . + 1/xn

1
Expert's answer
2021-10-30T10:36:32-0400


#include <iostream>
#include <math.h>


using namespace std;


int main()
{
   int n;
   cout<<"\nEnter n: ";
   cin>>n;
   int x;
   cout<<"\nEnter x: ";
   cin>>x;
   float sum=0;
   for(int i=1;i<=n;i++){
       sum+=(1.0/float (pow(x,i)));
   }
   cout<<"\nSum = "<<sum;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS