To get familiarity with arrays in C I'm trying to write a simple program to calculate average, standard deviation, and bubblesort from some numbers passed into an array. Yet I keep running into the same error in my average and stddev functions... It says "practice.c:X: error: lvalue required as left operand of assignment" AND
"practice.c:X: error: incompatible types when returning type ‘double (*)(int *, int)’ but ‘double’ was expected"
I feel that this is a very simple problem, but I am stumped.
Thanks!
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
const int SIZE = 10;
//average
double average(int x[], int SIZE)
{
double total = 0.0;
int i;
for (i=0; i < SIZE; i++)
{
total += x[i];
}
average = total / (SIZE-1);
return average;
}
//standard deviation
double stddev(int x[], int SIZE, double average)
{
double total = 0.0;
int i;
for(i=0; i < 100; i++)
{
total += (average - x[i]) * (average - x[i]);
}
stddev = sqrt(total/(SIZE-1));
return stddev;
}
//bubblesort
void bubblesort(int x[], int SIZE)
{
int i;
int j;
int k;
for(i = 0; i < (SIZE - 1); i++){
for(j = 0; j < (SIZE -1); j++){
if(x[j] > x[j + 1]){
k = x[j];
x[j] = x[j+1];
x[j+1] = k;
}
}
printf("%d", x[i]);
}
int main(void)
{
int i = 0;
for(i = 0; i <= 10; i++)
{
scanf("%d", &x[i]);
printf("%d\n", x[i]);
}
}

New Topic/Question
Reply



MultiQuote




|