In the array declaration, you have undefined behavior because you used the wrong size:
main() { int i, t[i], d, sum, product; i = 0; printf("Enter your natural numbers. \n"); while (i <= 9) { printf("Number %d : ", i + 1); scanf( "%d", &t[i]); i++; }
You probably wanted to announce
t[MAX_BOUND+1];
( MAX_BOUND will be incorrect since you are using the t[MAX_BOUND] element).
At the point where t declared, i has an undefined value (it is unlikely that it is 0).
With an indefinite array size, access t[i] causes even more indefinite values ââ(and again this behavior is undefined if i >= sizeof t / sizeof t[0] ).
Printed part
if(sum == t[i]) printf("%d is a perfect number. \n", t[i]); else product = product * t[i];
should be moved after the cycle is used to determine the sum of the divisor. At the same time, inside the cycle, you multiply product by t[i] total t[i] - 1 time (or t[i] - 2 , if one of the intermediate sums is t[i] ), if t[i] not perfect, and t[i]/2-1 if t[i] perfect. In addition, you print t[i]/2 times for perfect numbers and once for plentiful numbers if one of the subtotals is t[i] (I ignore the theoretical possibility of odd perfect numbers, if any, they are too big for int )
Executing this result gives the correct result.
source share