Need help with finding the average and standard deviation of an array
Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int average(int population[], int count) {
int i = 0;
int sumofarray = 0;
for (i=0; i<100; i++);{
sumofarray += population[i];
}
return sumofarray / count ;
}
int stddev(int population[], int count, int averageofarray) {
int difference = 0;
int differencesquared = 0;
int sumofdifferencesquared = 0;
int averageofdifferencesquared = 0;
int i = 0;
for (i=0; i<100; i++);
{
difference = population[i] - averageofarray;
differencesquared = difference * difference;
sumofdifferencesquared += differencesquared;
averageofdifferencesquared = sumofdifferencesquared / count;
}
return sqrt(averageofdifferencesquared);
}
main()
{
int count = 0;
int i = 0;
int averageofarray = 0;
int standarddeviation = 0;
int population[100];
for (i=0; i<100; i++)
{
population[i] = rand()%100;
count++;
}
averageofarray = average(population, count);
standarddeviation = stddev(population, count, averageofarray);
printf("The array you entered consists of these numbers:\n");
for(i=0;i<100;printf("%d ",population[i]), i++);
printf("\nThe average of the population is %d\n", averageofarray);
printf("The standard deviation of the population is %d", standarddeviation);
return 0;
}
I have to use a function for average and a function of standard deviation, which each call the randomly generated array and spit out their values to the prints. I'm not supposed to use pointers and am just getting stuck somewhere and this is due tomorrow morning. Any help would be greatly appreciated since I'm really new to C and programming in general.
Not getting an accurate average now.