The problem in your program comes from the subject selection (after adding the missing }
):
s=random_number_creator(5,0);
Will return a random number between 0 and 4 included.
To correct this, just replace this line by
s=random_number_creator(7,0);
To pick a number between 0 and 6. So the cou
variable will be able to reach 0
Your code can be improved:
Instead of this kind of block:
for(i=0;i<5;i++)
{
printf("final entery \n");
for(j=0;j<9;j++)
printf(" %d",oldpop.days[i][j]);
}
Create a function, learn to use printf
:
void print_table(struct pop pop, const char *label)
{
int i, j;
printf("\n%s\n", label);
for (i=0;i<5;i++)
{
for (j=0;j<9;j++)
{
printf(" %5d",pop.days[i][j]);
}
}
}
And use it this way
print_table(oldpop, "oldpop");
2
solved My C code for a genetic algortihtm is not functioning, it dosent enter into the if condition