Have been trying to learn C and complete an assignment that gives the RMS of a set of input numbers but the program crashes when run. Any advice appreciated on what's wrong with the code?
Code:
#include <stdio.h>
#include <math.h>
double RMS(double *x, int N)
{
int i;
double sum =0.0;
for (i=0; i<N; i++)
{
sum = sum + pow(x[i],2);
}
double question = sum/N;
sqrt (question);
return question;
}
int main()
{
int i, N;
double question;
double x [N];
printf("Enter the number of values in the sequence please: \n");
scanf("%d", &N);
for (i=0;i<N;i++)
{
printf("Enter the numbers in the sequence please: \n");
scanf("%lf", &x[i]);
}
question = RMS(x,N);
printf(" The RMS of your selected numbers is: %f. \n", RMS);
return 0;
}