63 049
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #26145 in C++ for Alpha

Question #26145
write a C++ program that uses a while loop to both display each term and determine the sum of a geometric series having a=1, r=0.5, n=10. Make sure your program displays the value it has calculated.
a+ ar + apow(r, 2) + ... + arpow(r, n-1)
Expert's answer
#include <cstdio>

using namespace std;

int main(int argc, char *argv[])
{
double a = 1, r = 0.5, s = 0;
int n = 10;
for (int i = 0; i < n; i++)
{
& printf("a_%d = %lf\n", i, a); //display current term
& s += a; // add it to sum
& a *= r; // calculate next term
}
printf("s = %lf\n", s); // display total 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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions