title: Shortest amount of consecutive 1's in a column in C
body: <p>I'm learning C language and I'm stuck doing this exercise and I don't know really how to solve it:</p>
  
  <ul>
  <li>Having a 1's and 0's matrix, find the shortest amount of consecutive 1's in any column.</li>
  </ul>
  
  <p>An example</p>
  
  <pre><code>1 0 1 1 
  1 1 1 1
  0 1 1 1
  1 1 1 1
  1 1 1 1
  </code></pre>
  
  <p>In this case the shortest amount is 2 consecutive 1 in the left column.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(){
  
      int i, j;
      int a[100][100];
      int minimum=999999;
      int columns,rows;
  
      printf("Number of Rows:");
      scanf("%i",&amp;rows);
  
      printf("Number of Columns:");
      scanf("%i",&amp;columns);
  
      for (i=0;i&lt;rows;i++) {
          for (j=0;j&lt;columns;j++) {
              scanf("%i",&amp;a[i][j]);
          }
      }
  
      for (j=0;j&lt;columns;j++) {
          int count_1s=0;
  
          for (i=0;i&lt;rows;i++) {
              if (a[i][j]==1) {
                  count_1s++;
              }   
              else {
                  count_1s=0;
              }
          }
  
          if(count_1s&gt;0&amp;&amp;count_1s&lt;minimum) {
              minimum=count_1s;
          }
          printf("%i ",count_1s);
      }
      printf("%i\n",minimum);
  }
  </code></pre>