C Language Examples - Finding All Factors of an Integer
If a*b=c (where a, b, and c are all integers), then we call a and b the factors of c.
Example
#include
<
stdio.h
int
main
(
)
{
int
number
,
i;
printf
(
"
Enter an integer:
"
)
;
scanf
(
"
%d
"
,&
number
)
;
printf
(
"
The factors of %d are:
"
,
number
)
;
for
(
i
=
1
;
i
<=
number
; ++
i
)
{
if
(
number
%
i
==
0
)
{
printf
(
"
%d
"
,
i
)
;
}
}
return
0
;
}
Running result:
输入一个整数: 60
60 的因数有: 1 2 3 4 5 6 10 12 15 20 30 60
C Language Examples