Can you help me to change this program to work with a masive.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <cmath>
using namespace std;
double f (int x, int n)
{
double sum = 0;
for (int i = 1; i <= n; ++i)
sum += pow((double)x,(double)i)/i;
return sum;
}
int main()
{
int x, n;
cout << "x = "; cin >> x;
cout << "n = "; cin >> n;
cout << "Result: " << f(x,n) << endl;
system ("pause");
return 0;
}
|
Last edited on
What you want to calculate with massive???
Oh, shouldn't you be using pow(x,2)
? Or better yet, x*x
.
Last edited on
wherever importance ัะพ joint