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)
1
Expert's answer
2013-03-12T12:42:07-0400
#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
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment