Test instructions: A number in addition to all factors other than itself, the resulting number if less than itself, output deficient, otherwise output abundant, if equal, output perfect
The core of the problem: to ask for all the factors other than itself
int sum=1, I; for (i=2; i<n;i++) { if(n%i==0) sum+ =i; }
A number if divided by less than his number starting from 2, if n%i==0, stating that can n be divisible by I, I was one of his factors, sum+=i, again let I++,i to n-1 end
#include <stdio.h>#include<stdlib.h>intMain () {intN; printf ("Perfection output\n"); while(SCANF ("%d", &n)! =EOF) { if(n==0) {printf ("END of output\n"); Break; } Else if(n==1) printf ("%5d deficient\n", N); Else { intsum=1, I; for(i=2; i<n;i++) { if(n%i==0) Sum+=i; } if(sum<n) printf ("%5d deficient\n", N); Else if(sum==n) printf ("%5d perfect\n", N); Elseprintf"%5d abundant\n", N); } }}
poj1528---(number theory)