Reputation: 55
I have a variable which is declared using a 'typedef' data type and it has array. when i do a operation divide (/) it says invalid operations. this is the code sample :
const int n = 10;
typedef float matriks[100][100];
typedef float vektor[100];
matriks A;
vektor b;
vektor x;
void Sulih_Mundur (matriks A, vektor b, int n, vektor x){
int j,k;
float sigma;
x[n]=b[n]/A[n,n]; //error here
for(k=n-1;k<1;k--){
sigma=0;
for(j=k+1;j>=n;j++){
sigma=sigma+A[k,j]*x[j];
}
x[k]=(b[k]-sigma)/A[k,k];
}
}
i got error on x[n]=b[n]/A[n,n] it says invalid operands / to binary (have float and float) i dont understand which one is the problem because i used the same data types there. and one integer variabel to access the array. thank you...
Upvotes: 2
Views: 136
Reputation: 223872
x[n]=b[n]/A[n,n];
This is not the proper syntax for indexing a 2D array. The ,
here is actually the comma operator, which discards the left operand and evaluates to the right operand, so A[n,n]
is the same as A[n]
. So then you're attempting to assign a 1D array of float
to a float
which is the error you're getting.
What you want is:
x[n]=b[n]/A[n][n];
Do the same for other references of A
.
Upvotes: 4