-2

Is there anything wrong in these "for" loops? About syntax..? It compiles. The results start to increase while the program running, without any physical sense. i and j indexes are right. These loops are part of a long code but after debugging it seems that the mistake is not anywhere else.

for (i=0; i< *nbox; i++)  {
    for(j=0; j< *m1;j++) {
    bn[i][j] =bn[i][j]/dx[1];
                    }
    for(j=0; j< *m2;j++) {
    cn[i][j] =cn[i][j]/dx[1];
     }
}

for (i=0; i<=*npmax-1; i++)  {

    for(j=0; j< *m1;j++) {
        partic[j][i]= partic[j][i]*dx[1];
    }
    for(j=0; j< *m2;j++) { 
        partic[j+ *m1][i]=partic[j+ *m1][i]*dx[1];
    }
}

Thanks!

mouviciel
  • 66,855
  • 13
  • 106
  • 140

1 Answers1

1

You reuse the i index inside the first loop. Change it to something else and it should fix your problem.

Sorin
  • 11,863
  • 22
  • 26
  • What do you mean..? The two loops are separated, independent. They are inside the same c file, but in separated subprograms.. – beginner2707876 Nov 28 '13 at 10:27
  • @beginner2707876 - well, why not use local i's? You're just confusing us because we cannot see the scope of your indexes. – Martin James Nov 28 '13 at 10:41