|
发表于 2022-10-4 17:23:18
|
显示全部楼层
- #include <stdio.h>
- void foo(int n)
- {
- int b , c , d[200] , i ;
- for(c = 0 , i = 1 ; i < n ; i ++) if(! (n % i)) d[c ++] = i ;
- for(i = 0 , b = 0 ; i < c ; i ++) b += d[i] ;
- if(b == n) {
- printf("%3d its factors are : %d" , n , d[0]) ;
- for(i = 1 ; i < c ; i ++) printf(",%d" , d[i]) ;
- printf("\n") ;
- }
- }
- int main(void)
- {
- int i ;
- for(i = 2 ; i <= 1000 ; i ++) foo(i) ;
- }
复制代码
编译、运行实况:
- D:\[00.Exerciese.2022]\C>g++ -o x x.c
- D:\[00.Exerciese.2022]\C>x
- 6 its factors are : 1,2,3
- 28 its factors are : 1,2,4,7,14
- 496 its factors are : 1,2,4,8,16,31,62,124,248
- D:\[00.Exerciese.2022]\C>
复制代码 |
|