-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwork3-25-3.c
More file actions
35 lines (30 loc) · 866 Bytes
/
work3-25-3.c
File metadata and controls
35 lines (30 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <math.h>
void main()
{
int num, temp, sum;
for(num = 1;num < 1000;num++)
{
sum = 0;//每次循环前初始化sum
//遍历一遍比num小1的数到1的区间
for(temp = num-1;temp >= 1;temp--)
{
if(num % temp == 0)//如果num除以这个区间里的数余为零,那么这个
{ //数肯定是num的因子
sum = sum + temp;//将这个数累加到sum里
}
}
// printf("%d\n",sum);
if(num == sum)//将num与它的因子和sum作比较,如果相等,说明找到了
{
printf("%d:its factors are ", num);
//重复一遍之前求因子的过程来输出所有因子
for(temp = num-1;temp >= 1;temp--)
{
if(num % temp == 0)
printf("%d ", temp);
}
printf("\n");
}
}
}