#include<stdio.h>
//定义一个函数factorsum(),功能是返回number的因子和;
int factorsum(int number){
int i,factor,sum=0;
for(i=1;i<number;i++){
factor=number%i;
if(factor==0){
sum=sum+i;
}
}
return sum;
}
int main(){
int result,i,m,n;
printf("输入任意两个正整数:\n");
scanf("%d%d",&m,&n);
if(m<=1&&n<=1000) {
for (i = m; i <= n; i++) {
result = factorsum(i);
if (result == i) {
printf("%d为完数\n", i);
}
}
}else{
printf("invalid!\n");
}
return 0;
}
C语言输出m-n之间的所有完数
于 2023-10-23 21:09:31 首次发布