Note that there are some explanatory texts on larger screens.

plurals
  1. POC two dimensional array smallest gets biggest instead
    primarykey
    data
    text
    <p>I am new to stackoverflow as am new to programming, yet am not really a 'professional and enthusiast programmer'. Enthusiast maybe but not professional... </p> <p>In a part of some beginner code of mine i have a two dimensional array <code>diff[i][j]</code>, where the value is zero wherever <code>i==j</code>. I am trying to get the smallest value in each row but not the zero value...</p> <p>the part of the code (under construction) that searches the smallest of the first row is:</p> <pre><code>i=1; double smallest; for ( j=1 ; j&lt;=n ; j++ ) { smallest = diff[i][j]; if ( j!=i &amp;&amp; diff[i][j] &lt; smallest ) smallest = diff[i][j]; } printf("\n %lf\n", smallest); </code></pre> <p>however, the result is always the biggest number not the smallest. Anyone knows why??</p> <p>P.S. I'd be thankful for any suggestion or comment of dealing with stackoverflow.com and the way i asked my question, since am new here... thank you in advance...</p> <p>EDIT after the answers below, i decided to make the i=1 a special case and make two separate functions for both cases... however, when i try to assign j to other variable i failed... in the previous code:</p> <pre><code>if (j!=i &amp;&amp; diff[i][j]&lt;smallest) {smallest=diff[i][j]; d=j} </code></pre> <p>declared d previously and everything... when i print d it prints a random number >maybe the memory location content... tried for debugging to assign an initial value - with the declaration - and when printing it came out the initial value... the point is i want d to hold the column where the smallest value is... how can i acheive that??</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload