Today what do you meet? What a look, "count them" is not it ~
Title: If a number is exactly equal to the sum of its factors, this number is called "count them." E.g. 6 = 1 + 2 + 3. After programming to find all the numbers less than 1000.
Brief Analysis: All factors found through a number of cycles, and the factor into the array, it is confirmed that determines whether the number of complete cycle of the array and is equal to the number.
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int i, n, t = 0;
int a[1000];
for(n = 2; n < 1000; n++){
t=0;
for(i = 1; i < n; i++){
if((n % i) == 0)
a[i-1] = i;
else
a[i-1] = 0;
t += a[i-1];
}
if(n == t)
printf("%d ",n); //在内循环外执行,你能想明白的!
}
return 0;
}