0

Just Started C in University, first time doing it and the first program i had to write was one that required someone to be able to enter 5 random numbers and get the average of the 5 numbers, the highest/lowest of the 5 numbers and then finally the standard deviation of the 5 numbers.

i managed to get the mean/highest/lowest working but cant seem to get the standard deviation to work, any help is greatly appretiated, but remember im still a noob at C :)

Here is my code:

```
#include#include <stdio.h>
#include <cmath>
void main()
{
int x; //this is the counter
int myarray[5];
int deviationmean[5];
int highestvalue=0;
int nothighest=0;
int lowestvalue;
int notlowest;
int total;
int mean;
int standardtotal=0;
int z=0;
float standarddeviation=0;
for (x=0;x<5;x++)
{
printf("Enter number %d: ",x);
scanf("%d",&myarray[x]); //Enter Numbers
}
total=myarray[0]+myarray[1]+myarray[2]+myarray[3]+myarray[4];
mean=total/5;
printf("\n\nThe Average of the given numbers is %d", mean); //This is the Average
for (x=0;x<5;x++)
{
if(myarray[x]>highestvalue)
{
highestvalue=myarray[x]; //Highest Number
}
else
{
nothighest=myarray[x];
}
}
printf("\nThe Highest Value is %d", highestvalue);
lowestvalue=highestvalue;
for (x=0;x<5;x++)
{
if(myarray[x]<lowestvalue)
{
lowestvalue=myarray[x]; //Lowest Number
}
else
{
notlowest=myarray[x];
}
}
printf("\nThe Lowest Value is %d\n", lowestvalue);
for(x=0;x<5;x++)
{
deviationmean[x]=myarray[x]-mean;
}
standardtotal=deviationmean[0]+deviationmean[1]+deviationmean[2]+deviationmean[3]+deviationmean[4]+deviationmean[5];
z=standardtotal/5;
z=(float)z;
if(z<0)
{
standarddeviation=sqrt((float)-z);
}
else
{
standarddeviation=sqrt((float)z);
}
printf("The Standard Deviation is %f\n\n", standarddeviation);
}
```