参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); // divisor用来记录每个因子 int[] divisor = new int[1000]; for(int i = 6; i <= n; i++) { int sum = 0;// 总和 int cnt = 0;// 因子的数量 // 枚举因子 for(int j = 1; j < i; j++) { if(i % j == 0) { sum += j; divisor[cnt++] = j; } } if(sum == i) { System.out.print(i + " its factors are "); for(int j = 0; j < cnt; j++) { System.out.print(divisor[j] + " "); } System.out.println(); } } } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:953 |
【金明的预算方案】 (C++代码)浏览:989 |
C语言程序设计教程(第三版)课后习题6.8 (C++代码)浏览:611 |
简单的a+b (C语言代码)浏览:869 |
printf基础练习2 (C语言代码)浏览:792 |
简单的a+b (C语言代码)浏览:620 |
C语言训练-自由落体问题 (C语言代码)浏览:645 |
循环入门练习5 (C语言代码)浏览:890 |
蚂蚁感冒 (C语言代码)浏览:810 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:565 |