title: My program return sometime true, but not always Codewars question "Are they same"
body: <p>i a newbie i am stuck on this question from Codewars. The question is that;</p>
  
  <blockquote>
    <ul>
    <li><p>"Given two arrays a and b write a function comp(a, b) (compSame(a, b) in Clojure) that checks whether the two arrays have the "same" elements, with the same multiplicities. "Same" means, here, that the elements in b are the elements in a squared, regardless of the order."*</p>
    
    <p>a = [121, 144, 19, 161, 19, 144, 19, 11]<br>
      b = [121, 14641, 20736, 361, 25921, 361, 20736, 361]</p>
    
    <p>comp(a, b) returns true because in b 121 is the square of 11, 14641 is the 
      square of 121, 20736 the square of 144, 361 the square of 19, 25921 the 
      square of 161, and so on.</p>
    
    <p>If we change the first number to something else, comp may not return true 
      anymore:</p>
    
    <p>a = [121, 144, 19, 161, 19, 144, 19, 11]<br>
       b = [132, 14641, 20736, 361, 25921, 361, 20736, 361]</p>
    
    <p>comp(a,b) returns false because in b 132 is not the square of any number of a.</p></li>
    </ul>
  </blockquote>
  
  <p>I think an algorithm with check all array but i can't make it possible.It is C language. I am writing codes on Visual Studio and this is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;math.h&gt;
  int tempVal1;
  int tempVal2;
  
  bool comp(int *a, int *b, size_t sizeArray)
  {
      if (sizeArray == 0 || sizeArray == 0)
          return false;
  
      for (int k = 0; k &lt; sizeArray; k++)
      {
  
          for (int i = 0; i &lt; sizeArray; i++)
          {
              if (a[k] == sqrt(b[i]))
                  tempVal1 = 1;
              else
                  tempVal1 = 0;
              printf("%d", tempVal1);
          }
      }
      for (int k = 0; k &lt; sizeArray; k++)
      {
          for (int i = 0; i &lt; sizeArray; i++)
          {
              if (b[k] == (a[i] * a[i]))
                  tempVal2 = 1;
              else
                  tempVal2 = 0;
              printf("%d", tempVal2);
          }
      }
  
      printf(" tempval1 : %d\n", tempVal1);
      printf(" tempval2 : %d\n", tempVal2);
  
      if (tempVal1 * tempVal2)
          return true;
      return false;
  }
  
  int main() {
  
      bool result;
      int a[8] = { 121, 144, 19, 161, 19, 144, 19, 11 };
      int b[8] = { 121 * 121, 144 * 144, 19 * 19, 161 * 161, 19 * 19, 144 * 144, 362, 11 * 11 };
      result = comp(a, b, 8);
      printf("%d\n", result);
  }
  </code></pre>