Finding the perfect numbers between 1 - 1000
If you're trying to shorten it, there are only 3 perfect numbers up to 1000: just list 6, 28, and 496.

If you're trying to speed it up, an array of 1000 numbers is small enough to stay reasonably cache-resident: you can compute all divisor sums together faster than you can compute each of them one at a time.  This is similar to how you can sieve a long interval for primes much faster than you can test each number individually for primality.  Code fragment:

for(int i=1; i&lt;=n/2; i++) {
  for(int x=2*i; x&lt;=n; x+=i) {
    divisor_sum[x] += i;
  }
}


The length of the inner loop is O(n/i), which gets small very quickly, making the total cost O(n log n), whereas your double loop is O(n^2).