C Language Example - Find all factors of an integer

C Language Examples

If a*b=c (where a, b, c are all integers), then we call a and b 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; }

Run result:

输入一个整数: 60
60 的因数有: 1 2 3 4 5 6 10 12 15 20 30 60

C Language Examples

other extensions