[Solved] I need help writing Geometric series in c++ [closed]


It sounds like you’re asking about specifiying arguments. Simply put, in a function’s declaration, you can specify arguments passed to it, ie

int foo(int bar) {
    return bar;
}

In your case, assuming the code you provided is correct, you’d simply have

int foo(int A, int n) {
    int term, sum = 0;
    for(int i = 1; i <= n; i++)
    {
        term = A;
         for(int j = 1; j < i; j++)
              term = term * A;
         sum = sum + term;
    }
    return sum;
}

You can then later call foo, by passing in A and n; ie

auto out = foo(3,2);

Where a = 3, and n = 2.

1

solved I need help writing Geometric series in c++ [closed]