title: c programming - printing sequence of sum of squared digits (as an array) for a potential happy number
body: <p>I have this assignment for my intro to C programming class and part of my code has to find the sequence of the sum of square digits of a number in order to determine after if the given number is a happy number (sum of square digits = 1)</p>
  
  <p>Here's part of my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  </code></pre>
  
  <p>// The sum of square digits function</p>
  
  <pre><code>int sqd (int x) {
  
  int sum = 0;
  
  while (x &gt; 0) {
  
      sum = sum + pow(x%10, 2);
      x = x/10;
  }
  return sum;
  }
  </code></pre>
  
  <p>// The search function</p>
  
  <pre><code>int search (int a[], int val, int size) {
  
      int i;
  
      for (i = 0; i &lt; size; i++) {
          if (a[i] == val) {
              return 1;
          }
      }
  
     return 0;
  }
  </code></pre>
  
  <p>// The main program</p>
  
  <pre><code>void main () {
  
      int a [1000] = {0};
      int N;
      int count = 1;
      int j;
  
      printf("Please enter the potential happy number:\n", N);
  
      scanf ("%d", &amp;N);
  
      a[0] = N;
      a[count] = sqd (N); 
  
      do {    
          a[count] = sqd (a[count-1]);
          count++;
      } while (search (a, a[count], count));
  
      for ( j = 0; j &lt;= count; j++) {  
          printf("%d\n", a[j]);
      }
  }
  </code></pre>
  
  <p>It only prints the first three sums in the sequence. I really don't know how to make it work. </p>
  
  <p>Thank you in advance</p>