1000以内完数

完数:一个数字的所有约数除了本身相加,等于这个数字:例如

6:1+2+3=6;

28:1+2+4+7+14=28;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 完数
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i =2; i < 1000; i++)
            {
                int l=0;
                for (int j = 1; j <=i-1; j++)
                {
                    if (i % j == 0 )
                    {
                        l = l + j;
                    }
                }
                if (l==i)
                {
                    label2.Text =label2.Text+ l.ToString() + ",";
                }
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43437202/article/details/85546383