# Square Roots?!

Hello guys,

Got a bit of a question here. I'm trying to get the standard deviation of a set of numbers and according to my instructions for the assignment:

Root of:(Sums squared - (Sums squared/total nums)) / (total nums - 1)
would produce the standard deviation of the number set.

Now the test numbers I'm using(are floating point if it matters) are: 3.0, 3.0, 2.0, 3.0, 2.0, 3.5 and it's producing a standard deviation of: 45.375 without the root(I don't know how to produce a square root in code). And that seems awfully large, but I had another friend tell me he thought the instructor was crazy and you didn't need the square root for getting standard deviation. Below the code:

[code]
/*****************************************************************************
* Programmer Name : Christopher Sims *
* Program Name : Mean_Dev.c *
* Program Date : 30-Oct-2003 *
* Input : Integer/Float Numerics *
* Output : Number of #s, Mean, and standard deviation *
*****************************************************************************/

#include
#include

/* Prototype Declarations */

void main();
void intro();
void getnum(float *a1, int *c1, float *a2);/*made changes*/
float getmean(float, float);
float getdev(float, float);
void displayresults(int, float, float);
void main()
{
/* Local Variable Declaration */
float a1 = 0; /* Accumulator for numbers obtained via getnum */
float a2 = 0; /* Second Accumulator for adding the squares of numbers in a1 */
int c1 = 0; /* Counter to hold an amount for how many numbers were entered */
float mean; /* Average of all numbers added */
float stddev; /* Standard Deviation of numbers */

intro();
getnum(&a1, &c1, &a2);
mean = getmean(a1, c1);
stddev = getdev(a1, c1);
displayresults(c1, mean, stddev);

printf("

a1value: %f, c1value: %d, a2value: %f." , a1, c1, a2);
printf("
currentmean: %f standard deviation: %f" , mean, stddev);
}

void intro()
{
printf("

printf("
the numbers in float form, will give you the mean");
printf("
and the standard deviation of those numbers.");
printf("

Float form is any number entered with decimals, such as 3.0");
}
void getnum(float *a1, int *c1, float *a2)/*made changes*/
{
/* Local Variable Definitions */

float x = 1; /* Placeholder for entry */
float y; /* a1 placeholder */
float z; /* a2 placeholder */
int c; /* counter */

printf("

printf("
Enter a 0 to continue past after all your numbers are entered.");
printf("

");

c=0;
y=0;
z=0;
while(x != 0)
{
scanf("%f", &x);
if (x != 0)
{
c++;/*made change because c was counting 0 also*/
}
y = y + x;
z = z + (x * x);
}
*a1 = y;
*a2 = z;
/*removed return*/
}

float getmean(float a1, float c1)
{
return (a1 / c1);
}

float getdev(float a1, float c1)
{
/* Local Variable Declaration */
float sumsq; /* Sum Squared used in calc */
float stddev; /* Standard Deviation of numbers */

sumsq = (a1 * a1);
stddev = (sumsq - (sumsq / c1)) / (c1 - 1);
return stddev; /* Return stddev to main */
}

void displayresults(int c1, float mean, float stddev)
{
printf("

Results are as follows.");
printf("
Numbers Entered: %d." , c1);
printf("
Average/Mean of #'s: %f.", mean);
printf("
Standard Deviation: %f.", stddev);
printf("

Thanks for using my program.");
}
[/code]

If you can tip me as how to produce a root(if it's necessary) or concur with the other that my instructor is indeed crazy.
I appreciate the help.

[red]
Waylander420
[/red]

• : Hello guys,
:
: Got a bit of a question here. I'm trying to get the standard deviation of a set of numbers and according to my instructions for the assignment:
:
: Root of:(Sums squared - (Sums squared/total nums)) / (total nums - 1)
: would produce the standard deviation of the number set.
:
: Now the test numbers I'm using(are floating point if it matters) are: 3.0, 3.0, 2.0, 3.0, 2.0, 3.5 and it's producing a standard deviation of: 45.375 without the root(I don't know how to produce a square root in code). And that seems awfully large, but I had another friend tell me he thought the instructor was crazy and you didn't need the square root for getting standard deviation. Below the code:
:
: [code]
: /*****************************************************************************
: * Programmer Name : Christopher Sims *
: * Program Name : Mean_Dev.c *
: * Program Date : 30-Oct-2003 *
: * Input : Integer/Float Numerics *
: * Output : Number of #s, Mean, and standard deviation *
: *****************************************************************************/
:
: #include
: #include
:
: /* Prototype Declarations */
:
: void main();
: void intro();
: void getnum(float *a1, int *c1, float *a2);/*made changes*/
: float getmean(float, float);
: float getdev(float, float);
: void displayresults(int, float, float);
: void main()
: {
: /* Local Variable Declaration */
: float a1 = 0; /* Accumulator for numbers obtained via getnum */
: float a2 = 0; /* Second Accumulator for adding the squares of numbers in a1 */
: int c1 = 0; /* Counter to hold an amount for how many numbers were entered */
: float mean; /* Average of all numbers added */
: float stddev; /* Standard Deviation of numbers */
:
: intro();
: getnum(&a1, &c1, &a2);
: mean = getmean(a1, c1);
: stddev = getdev(a1, c1);
: displayresults(c1, mean, stddev);
:
: printf("

a1value: %f, c1value: %d, a2value: %f." , a1, c1, a2);
: printf("
currentmean: %f standard deviation: %f" , mean, stddev);
: }
:
: void intro()
: {
: printf("

: printf("
the numbers in float form, will give you the mean");
: printf("
and the standard deviation of those numbers.");
: printf("

Float form is any number entered with decimals, such as 3.0");
: }
: void getnum(float *a1, int *c1, float *a2)/*made changes*/
: {
: /* Local Variable Definitions */
:
: float x = 1; /* Placeholder for entry */
: float y; /* a1 placeholder */
: float z; /* a2 placeholder */
: int c; /* counter */
:
: printf("

: printf("
Enter a 0 to continue past after all your numbers are entered.");
: printf("

");
:
: c=0;
: y=0;
: z=0;
: while(x != 0)
: {
: scanf("%f", &x);
: if (x != 0)
: {
: c++;/*made change because c was counting 0 also*/
: }
: y = y + x;
: z = z + (x * x);
: }
: *c1 = c; /*made changes*/
: *a1 = y;
: *a2 = z;
: /*removed return*/
: }
:
: float getmean(float a1, float c1)
: {
: return (a1 / c1);
: }
:
: float getdev(float a1, float c1)
: {
: /* Local Variable Declaration */
: float sumsq; /* Sum Squared used in calc */
: float stddev; /* Standard Deviation of numbers */
:
: sumsq = (a1 * a1);
: stddev = (sumsq - (sumsq / c1)) / (c1 - 1);
: [green]// return stddev; /* Return stddev to main */[/green]
: [red] return (sqrt(stddev));[/red]
: }
:
: void displayresults(int c1, float mean, float stddev)
: {
: printf("

Results are as follows.");
: printf("
Numbers Entered: %d." , c1);
: printf("
Average/Mean of #'s: %f.", mean);
: printf("
Standard Deviation: %f.", stddev);
: printf("

Thanks for using my program.");
: }
: [/code]
:
: If you can tip me as how to produce a root(if it's necessary) or concur with the other that my instructor is indeed crazy.
: I appreciate the help.
:
: [red]
: Waylander420
: [/red]
:
To find the square root of a number, simply use the function sqrt(), defined in math.h. See [red]red[/red] in your code.

(from http://www.robertniles.com/stats/stdev.shtml)
[code]
x = one value in your set of data
avg (x) = the mean (average) of all values x in your set of data
n = the number of values x in your set of data

For each value x, subtract the overall avg (x) from x, then multiply
that result by itself (otherwise known as determining the square of
that value). Sum up all those squared values. Then divide that result
by (n-1). Got it? Then, there's [b]one more step... find the square root
of that last number[/b]. That's the standard deviation of your set of data.
[/code]
HTH

-Tony

• : : Hello guys,
: :
: : Got a bit of a question here. I'm trying to get the standard deviation of a set of numbers and according to my instructions for the assignment:
: :
: : Root of:(Sums squared - (Sums squared/total nums)) / (total nums - 1)
: : would produce the standard deviation of the number set.
: :
: : Now the test numbers I'm using(are floating point if it matters) are: 3.0, 3.0, 2.0, 3.0, 2.0, 3.5 and it's producing a standard deviation of: 45.375 without the root(I don't know how to produce a square root in code). And that seems awfully large, but I had another friend tell me he thought the instructor was crazy and you didn't need the square root for getting standard deviation. Below the code:
: :
: : [code]
: : /*****************************************************************************
: : * Programmer Name : Christopher Sims *
: : * Program Name : Mean_Dev.c *
: : * Program Date : 30-Oct-2003 *
: : * Input : Integer/Float Numerics *
: : * Output : Number of #s, Mean, and standard deviation *
: : *****************************************************************************/
: :
: : #include
: : #include
: :
: : /* Prototype Declarations */
: :
: : void main();
: : void intro();
: : void getnum(float *a1, int *c1, float *a2);/*made changes*/
: : float getmean(float, float);
: : float getdev(float, float);
: : void displayresults(int, float, float);
: : void main()
: : {
: : /* Local Variable Declaration */
: : float a1 = 0; /* Accumulator for numbers obtained via getnum */
: : float a2 = 0; /* Second Accumulator for adding the squares of numbers in a1 */
: : int c1 = 0; /* Counter to hold an amount for how many numbers were entered */
: : float mean; /* Average of all numbers added */
: : float stddev; /* Standard Deviation of numbers */
: :
: : intro();
: : getnum(&a1, &c1, &a2);
: : mean = getmean(a1, c1);
: : stddev = getdev(a1, c1);
: : displayresults(c1, mean, stddev);
: :
: : printf("

a1value: %f, c1value: %d, a2value: %f." , a1, c1, a2);
: : printf("
currentmean: %f standard deviation: %f" , mean, stddev);
: : }
: :
: : void intro()
: : {
: : printf("

: : printf("
the numbers in float form, will give you the mean");
: : printf("
and the standard deviation of those numbers.");
: : printf("

Float form is any number entered with decimals, such as 3.0");
: : }
: : void getnum(float *a1, int *c1, float *a2)/*made changes*/
: : {
: : /* Local Variable Definitions */
: :
: : float x = 1; /* Placeholder for entry */
: : float y; /* a1 placeholder */
: : float z; /* a2 placeholder */
: : int c; /* counter */
: :
: : printf("

: : printf("
Enter a 0 to continue past after all your numbers are entered.");
: : printf("

");
: :
: : c=0;
: : y=0;
: : z=0;
: : while(x != 0)
: : {
: : scanf("%f", &x);
: : if (x != 0)
: : {
: : c++;/*made change because c was counting 0 also*/
: : }
: : y = y + x;
: : z = z + (x * x);
: : }
: : *c1 = c; /*made changes*/
: : *a1 = y;
: : *a2 = z;
: : /*removed return*/
: : }
: :
: : float getmean(float a1, float c1)
: : {
: : return (a1 / c1);
: : }
: :
: : float getdev(float a1, float c1)
: : {
: : /* Local Variable Declaration */
: : float sumsq; /* Sum Squared used in calc */
: : float stddev; /* Standard Deviation of numbers */
: :
: : sumsq = (a1 * a1);
: : stddev = (sumsq - (sumsq / c1)) / (c1 - 1);
: : [green]// return stddev; /* Return stddev to main */[/green]
: : [red] return (sqrt(stddev));[/red]
: : }
: :
: : void displayresults(int c1, float mean, float stddev)
: : {
: : printf("

Results are as follows.");
: : printf("
Numbers Entered: %d." , c1);
: : printf("
Average/Mean of #'s: %f.", mean);
: : printf("
Standard Deviation: %f.", stddev);
: : printf("

Thanks for using my program.");
: : }
: : [/code]
: :
: : If you can tip me as how to produce a root(if it's necessary) or concur with the other that my instructor is indeed crazy.
: : I appreciate the help.
: :
: : [red]
: : Waylander420
: : [/red]
: :
: To find the square root of a number, simply use the function sqrt(), defined in math.h. See [red]red[/red] in your code.
:
: (from http://www.robertniles.com/stats/stdev.shtml)
: [code]
: x = one value in your set of data
: avg (x) = the mean (average) of all values x in your set of data
: n = the number of values x in your set of data
:
: For each value x, subtract the overall avg (x) from x, then multiply
: that result by itself (otherwise known as determining the square of
: that value). Sum up all those squared values. Then divide that result
: by (n-1). Got it? Then, there's [b]one more step... find the square root
: of that last number[/b]. That's the standard deviation of your set of data.
: [/code]
: HTH
:
: -Tony
:
:

Thank you Tony, that was most helpful.

[red]
Waylander420
[/red]