title: Sum of different numbers in an array
body: <p>I want to have a function that returns the sum of different (non duplicate) values from an array: if I have <code>{3, 3, 1, 5}</code>, I want to have sum of <code>3 + 1 + 5 = 9</code>.</p>
  
  <p>My attempt was:</p>
  
  <pre><code>int sumdiff(int* t, int size){
      int sum=0;
      for (int i=0; i&lt;=size;i++){
          for(int j=i; j&lt;=size;j++){
              if(t[i]!=t[j])
              sum=sum+t[i];
          }
      }
      return sum;
  }
  
  int main()
  {
      int t[4]={3, 3, 1, 5};
      cout &lt;&lt; sumdiff(t, 4);
  }
  </code></pre>
  
  <p>It returns <code>25</code> and I think I know why, but I do not know how to improve it. What should I change?</p>