ArrayList al;
int count;
for(int i=6;i<100;i++)
{
al=new ArrayList();
for(int j=1;j<i;j++)
{
if(i%j==0)
{
al.Add(j);
}
}
count=0;
for(int j=0;j<al.Count;j++)
{
count+=Convert.ToInt32(al[j]);
}
if(count==i)
{
listBox1.Items.Add(i);
}
}
int count;
for(int i=6;i<100;i++)
{
al=new ArrayList();
for(int j=1;j<i;j++)
{
if(i%j==0)
{
al.Add(j);
}
}
count=0;
for(int j=0;j<al.Count;j++)
{
count+=Convert.ToInt32(al[j]);
}
if(count==i)
{
listBox1.Items.Add(i);
}
}
int j=1;j<i
循环只要算到i的一半就可以了,
你自己琢磨一下。