This is the code I have written so far. Right now the code only gets the polynomial, later it will create the derivative. The error is not in the code itself. It runs until all the coefficients are input and then I get the bad access thing.

#include <iostream>
#include <cmath>
using namespace std;
double poly(double[], int);
double drv(double[], int, double);
int main ()
{
int n;
cout << "Enter the degrees of the polynomial: ";
cin >> n;
double c[n];
for (int i=n; i>=0; i--)
{
cout << "Enter the coefficient for the variable of degree " << i << ": ";
cin >> c[i];
}
cout << "The polynomial entered is: " << poly(c,n) << endl; //I think this is where it's messing up
return 0;
}
double poly(double c[], int n)
{
double sum=0.0;
double x;
for (int i=0; i<=n; i--)
{
sum+=c[i]*pow(x, i);
}
return sum;
}

You are allocating an array with a non-constant (line 15)

The compiler compiles it until it reaches the point where it's supposed to pick up from the function, so something is wrong with the function. The x is because I want it to say that it's the coefficient (c) times x^i, because later on in the program I need it to take the derivative.

If your intention is to use the pow() function, both parameters need to have actual values.
...meaning: The variable x needs a value before you use it.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :