Answer to Question #20842 in C++ for Priya Darshani

Question #20842
Write a program in c++ and algorithm to find the sum of 'n' term of a series
1-1/2+1/4-1/8+1/16+............
1
Expert's answer
2012-12-20T07:46:40-0500
#include <math.h>
#include "iostream"
using namespace std;

int main()
{
int i;
float s=0,k,h;
cout<<"Enter n : ";
cin>>i;

for(int t=0;t<i;t++){

s=s+1/(pow(2,t));

}

cout<<"Sum : "<<s<<endl;

system ("PAUSE");

}

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
APPROVED BY CLIENTS