Question: Identify the errors in the following C code and fix it so the program can run. #include #include int calculate(bool* genetic); int main() { int

Identify the errors in the following C code and fix it so the program can run.

#include

#include

int calculate(bool* genetic);

int main()

{

int i,j,g; //counters

int population=100;

bool genetic[10][7]; //population

//initializing population

for(i=0;i

{

for(j=0;j<7;j++)

{

//randomize the genetic

genetic[i][j]=rand()%2;

}

}

for(g=0;g<100;g++)

{

printf("generation %d ",g);

//Evaluation

int best=0;

for(i=1;i

{

if(calculate(genetic[best])

best=i;

}

//Reproduction

for(i=0;i

{

if(i!=best)

{

for(j=0;j<7;j++)

{

if(rand()%2)

genetic[i][j]=genetic[best][j];

else

genetic[i][j]=genetic[i][j];

//mutation

if(rand()%100<4)

genetic[i][j]=rand()%2;

}

}

}

printf("best calculate %d ",calculate(genetic[best]));

}

getchar();

return 0;

}

int calculate(bool* genetic)

{

return ( -genetic[0] + genetic[1] + genetic[2]

-genetic[3] + genetic[4] - genetic[5]

-genetic[6] );

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!