Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

Find the derivative. f(x) 8 3 4 mix X O 4 x32 4 x32 3 -4x - x2

Answered: 1 week ago

Question

7. General Mills

Answered: 1 week ago

Question

3. Describe the strategic training and development process.

Answered: 1 week ago