for (i=0;i<n;i++){ max=b[i][0]; min=b[i][0]; for (j=1;j<m;j++){ if (min>b[i][j]){ min=b[i][j]; admin=j; } if (max<b[i][j]){ max=b[i][j]; admax=j; } } printf ("\nΠ’ %d строкС ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ элСмСнт Ρ€Π°Π²Π΅Π½ %.2f, ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ %.2f", i, max, min); } 

The task is to find the maximum and minimum values ​​and swap them. The whole cycle works and the code works fine, but if inside for(i=0;i<nn;i++){...} after printf add

 b[i][admax]=min; b[i][admin]=max; 

That as soon as it reaches this line - the work of the cycle and the program in general ends

 Π’ 0 строкС ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ элСмСнт Ρ€Π°Π²Π΅Π½ 4,00, ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ 1,00 
  • 2
    I would like to look at all the code and data. So far - and if you do not have, say, less than the first or more of it - then what will your admin (respectively, admax )? I do not see the initialization of these variables, so that there in them is unknown. I would recommend to rewrite max=b[i][0]; min=b[i][0]; max=b[i][0]; min=b[i][0]; as max=b[i][admax=0]; min=b[i][admin=0]; max=b[i][admax=0]; min=b[i][admin=0]; - Harry
  • Thanks, now it works - dhvcc

1 answer 1

The variables admin, admax are not initialized by any value (garbage). Prog and crashes. It is necessary to add a condition under which cases these variables matter.

  • Thanks, helped - dhvcc