# Any Smart guy can figure this out? Should be simple problem.

• 11-18-2011
kevave
Any Smart guy can figure this out? Should be simple problem.
I am getting this error when want to compile.
Code:

```/tmp/ccmvPe9e.o: In function `stdData': problem.c:(.text+0x56b): undefined reference to `sqrt' collect2: ld returned 1 exit status```

And this is the "StdDate" below. Where is the problem? sqrt???

Code:

``` double stdData (double x[], int n)/* function to find the standard deviation */ {         int i;         double sum = 0, sum1 = 0;         double sum2, std;         for (i=0; i<n; i++){                 sum1 = sum1 + (x[i]*x[i]);                 sum = sum + x[i];         }         sum2 = (sum * sum)/(n*n);         std = sqrt(sum1- sum2);         return (std); }```
• 11-18-2011
Have you included math.h?
• 11-18-2011
kevave
Quote:

Have you included math.h?

Yes. I did do the math.h Could you look at my code and see if you can fix it??

Code:

```   Descrition: Implement a menu managing array data such that the program asks multiple questions to the user and executes the operation using the method he chooses. */ #include <stdio.h> #include <math.h> /*function definitions*/ double sumData (double x[], int n);//returns the sum of the given set. double medianData (double x[], int n);//returns the median of the given set. double stdData (double x[], int n);// returns the standad derivation of the given set. double rangeData (double x[], int n);//returns the range of the given set. void freqData (double x[], int n);//displays the frequency distribution in the given ranges. double meanData(double x[], int n);//returns the mean of the data set. void setData(double x[], int n);// returns the array as a whole. void bubble_sort(double x[], int n);//to search the array. int main() {         int size=100;         double array[size];         int i, x, c;         printf ("Please enter the size of you array:");         scanf ("%d", &size);         for (i=0; i<size; i++) {                 printf("Enter element %d of the array:", i);                 scanf("%lf", &array[i]);         }         printf("Please select a number among the following operations:\n");         printf("1.Display the data set\n2.Calculate the mean and");         printf("sum of the data set\n3.Calculate the median of the data set\n");         printf("4.Calculate the standard deviation of the data set\n5.");         printf("Find range of the data set\n6.Display a frequency distribution\n");         printf("7.Quit\n");         scanf("%d", &c);     while (c<1 || c>7) {                 printf("\aYou have entered an ivalid number; try again.\n");                 printf("Please select a number among the following operations:\n");                 printf("1.Display the data set\n2.Calculate the mean and");                 printf("sum of the data set\n3.Calculate the median of the data set\n");                 printf("4.Calculate the standard deviation of the data set\n5.");                 printf("Find range of the data set\n6.Display a frequency distribution\n");                 printf("7.Quit\n");                 scanf("%d", &c);         }         if (c==1) {                 setData (array, size); //call the function to display the array.         }         else if (c==2){// displays both the mean and sum.                 meanData(array, size);                 sumData(array, size);                 printf("mean of the data set:%f\n the sum is:%f\n", meanData(array, size), sumData(array, size));         }  else if (c==3){//displays median                 medianData(array, size);                 printf("median of the data set: %f\n", medianData(array, size));         }         else if (c==4){                 stdData(array, size); //to display the deviation.         printf("The standard deviation of the data set:%f\n", stdData(array, size));         }         else if (c==5){// Printing the range on the screen.                 rangeData(array, size);                 printf("The range of this data set is:%f\n", rangeData(array, size));         }         else if (c==6){//returning the frequency in interval ranges.                 freqData(array, size);         }         else if (c==7){//Quit the program.                 printf("The program ends here.\n");         }         return 0; } /*function definitions*/ void setData (double x[], int n)/* function to display the array pr set data*/ {         int i;         for (i=0; i<n; i++){                 printf("%f ", x[i]);         } } double meanData( double x[], int n)/* function to calculate the mean*/ {         int i;         double sum =0;         for (i=0; i<n; i++){                 sum = sum + x[i];         }         return (sum/n); } double sumData( double x[], int n)/*function to calculate the sum*/ {         int i;         double sum = 0;         for (i=0 ;i<n; i++){                 sum = sum + x[i];         }         return (sum); } void bubble_sort( double x[], int n)/* function to sort data in increasing order */ {         int i,j;         double temp;         for (i=0; i<n-1; i++){                 for (j=i+1; j<n; j++){                         if ( x[i] > x[j]){                                 temp = x[i];                                 x[i] = x[j];                                 x[j] = temp;                         }                 }         } } double medianData (double x[], int n) /*function to calculate the median of the data set */ {         double Middle;         int h1, h2;         bubble_sort(x,n);         if (n%2 == 0){/*if n is even */                 h1 = n/2;                 h2 = (n/2) - 1;                 Middle = ((x[h1] + x[h2])/2);         }         else { //if n is odd                 Middle = x[n/2];         }         return ( Middle ); } double stdData (double x[], int n)/* function to find the standard deviation */ {         int i;         double sum = 0, sum1 = 0;         double sum2, std;         for (i=0; i<n; i++){                 sum1 = sum1 + (x[i]*x[i]);                 sum = sum + x[i];                         }         sum2 = (sum * sum)/(n*n);         std = sqrt((sum1/n) - sum2);         return (std); } double rangeData(double x[], int n)/* calculting the range of the data set */ {         int i;         double max, min, range;         max = x[0];         min = x[0];  for (i = 0; i<n; i++){                 if( x[i] < min){//searching for the minimum element                         min = x[i];                 }                 if (x[i] > max){//searching for the maximum element                         max = x[i];                 }         }         range = max - min;//calculating the range         return (range); } void freqData (double x[], int n)/*displaying the frequency */ {         int i;         int freq1 = 0;         int freq2 = 0;         int freq3 = 0;         int freq4 = 0;         bubble_sort(x,n);/*sorting the array values */         for (i=0; i<n; i++){                 if (x[i] < 0){                         freq1 = freq1 + 1;                 }                 else if (x[i]>= 0 && x[i]<10){                         freq2 = freq2 + 1;                 }                 else if (x[i]>= 10 && x[i]<100){                         freq3 = freq3 + 1;                 }                 else {                         freq4 = freq4 +1;                 }         }//displaying ranges.         printf ("%s%13s\n", "Interval", "Frequency" );         printf ("(-inf , 0)%13d\n", freq1);         printf ("[0, 10)%10d\n", freq2);         printf ("[10, 100)%9d\n", freq3);         printf ("[100,+inf )%11d\n", freq4); }```
• 11-18-2011
brewbuck
• 11-18-2011
kevave
Quote:

Originally Posted by brewbuck

I did and I am getting this
gcc: lm: No such file or directory
• 11-18-2011
smokeyangel
http://cboard.cprogramming.com/c-pro...look-mine.html -- same guy, same question, same answer
• 11-18-2011
kevave
Quote:

Originally Posted by smokeyangel
http://cboard.cprogramming.com/c-pro...look-mine.html -- same guy, same question, same answer

Hey guys I got it!!!!! Thank you so much for your times! I am including a link below for everyone for lunch. FREE IHOP lunch.
• 11-18-2011
Tclausex
[QUOTE=kevave;1070123]Hey guys I got it!!!!! Thank you so much for your times! I am including a link below for everyone for lunch. FREE IHOP lunch.

Ugh, marketing spam? srsly?