整数a除以整数b(b≠0) 的商正好是整数而没有余数,我们就说b是a的因数。如果一个整数能够被另一个整数整除,那么这个整数就是另一整数的倍数。
#include <stdio.h>
int main() {
int num, i;
printf("Enter a positive integer: ");
scanf("%d", &num);
printf("Factors of %d are: ", num);
for (i = 1; i <= num; ++i) {
if (num % i == 0) {
printf("%d ", i);
}
}
return 0;
}
|
1 2 |
Enter a positive integer: 60 Factors of 60 are: 1 2 3 4 5 6 10 12 15 20 30 60 |
除教程外,本网站大部分文章来自互联网,如果有内容冒犯到你,请联系我们删除!