本帖最后由 jackz007 于 2021-3-24 12:56 编辑
这一句 改为 for(s = 0 , n = 1 ; n < i ; n ++)
我修改的代码#include <stdio.h>
int main(void)
{
int d[50] , i , j , k , n , s ;
for(i = 2 ; i < 1000 ; i ++) {
for(s = j = 0 , n = 1 ; n < i ; n ++) {
if(i % n == 0) {
s = s + n ;
d[j ++] = n ;
}
}
if(s == i) {
printf("%3d 是完数,它的因子有:%d " , i , d[0]) ;
for(k = 1; k < j ; k ++) printf(" %d" , d[k]) ;
printf("\n") ;
}
}
}
编译、运行实况D:\0002.Exercise\C>cl x.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
x.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/out:x.exe
x.obj
D:\0002.Exercise\C>x
6 是完数,它的因子有:1 2 3
28 是完数,它的因子有:1 2 4 7 14
496 是完数,它的因子有:1 2 4 8 16 31 62 124 248
D:\0002.Exercise\C>
|