当前位置: 代码迷 >> 综合 >> C#程序设计 A3.7 综合练习2-求完数(Console)
  详细解决方案

C#程序设计 A3.7 综合练习2-求完数(Console)

热度:84   发布时间:2023-10-20 15:29:25.0
  public A37Page() {Console.WriteLine("1000以内的完数为:");for (int i = 2; i <= 10000; i++){string str = "1";//用于存放完数的各个因子int s = 1; //用于存放各因子之和int a = 0;for (int j = 2; j <= (int)Math.Sqrt(i); j++){if (i % j == 0 && i != j){a = i / j; //用于存放满足条件两数之商s += j + a;//存放因子之和str += string.Format("+{0}+{1}", j, a);}}if (s == i)//完数判断{Console.WriteLine("结果显示:{0} = {1}", i, str);}}}

 

  相关解决方案