//you may be using another data type such as int
float b = 0;
//look into arrays to see how to instantiate them and fill in the values for your case
float xArray[] = {...};
float yArray[] = {...};
float x = 5; //or whatever value it has
float y = 10; //or whatever value it has
int i = 0; //loop counter
int n = /*whatever*/; //number of values
for(i = 0; i < n; i++) //arrays of size n are indexed 0..n-1
{
b += (xArray[i] - x) * (yArray[i] - y);
}
@chipp ko2dy specifically asked for C code. In C, all variable declarations need to be at the beginning of the block (I initialized i for good practice). Doing for(int i = 0; /*foo*/) is illegal in C.
@shacktar i tried your program recommendation, but there is an error said "pointer can only be subtracted by pointer"
i think it's incorrect to subtract x[i] with only x