I received the error: expected ';', ',' or ')' before numeric constant which i believe is due to me using the macro. The code is meant to calculate the answer to this formula based on a matrix of of MxM where M < 10. For this example, a 3x3 matrix was given to test the code and hence i tried to define M as 3.
#include "stdio.h"
#define M 3
float pfa(int CM[M][M], int M ,int index)
{
int i,j,k;
int numerator;
int denominator;
int answer;
for (i=0; i< M; i++){
if (i != index){
numerator += CM[i][index];
}
}
for (j=0;j<index;j++){
for (k=0; k<M; k++){
if (j != index){
denominator += CM[j][k];
}
}
}
answer = numerator/denominator;
return answer;
}
int main(void)
{
// Variable definitions
int index;
// Note: different initialisation list is needed for different M
int CM[M][M]={{60,2,3},{11,47,7},{27,14,24}};
for (index=0; index<M; index++){
printf("%f \n", pfa(CM,M,index));
}
//0.292308 answers if code is done correctly
//0.123077
//0.076923
}
float pfa(int CM[3][3], int 3 ,int index)<--int 3?