注册 登录
编程论坛 C++教室

新手求教。

thx354463637 发布于 2012-11-09 21:17, 321 次点击
#include<stdio.h>
void main()
{int i,j,counter=0,sum;
  for(i=1;i<=100;i++)
 { for(j=1,sum=0;j<=i-1;j++);
  {if(0 ==i%j)
    sum+=j;
  }
   if(sum==i)
   {printf("%d is a wanshu\n",i);
   counter++;
   }
  }
  printf("There are %d wanshu(s) between 1and100\n",counter);
}
 这个求完数的程序哪里有问题啊?
4 回复
#2
yuccn2012-11-09 22:26
#include<stdio.h>
 void main()
 {int i,j,counter=0,sum;
   for(i=1;i<=100;i++)
 { for(j=1,sum=0;j<=i-1;j++); // 这个地方多了个分号?
   {if(0 ==i%j)
     sum+=j;
   }
    if(sum==i)
    {printf("%d is a wanshu\n",i);
    counter++;
    }
   }
   printf("There are %d wanshu(s) between 1and100\n",counter);
 }
不知道你这个程序是干什么的哦。。wanshu是什么 不清楚~~
#3
thx3544636372012-11-09 23:14
回复 2楼 yuccn
就是拼音。 wan shu 完数  
实验结果是错误的
#4
zxd5432012-11-10 01:35
#include<stdio.h>
void main()
{
    int i,j,counter=0,sum;
    for(i=1;i<=100;i++)
    {
        sum=0;
        for(j=1;j<i;j++)//你每次循环sum=0 sum怎么累加 for()循环后怎么还能加分号?
        {
            if(i%j==0)
               sum+=j;
        }
        if(sum==i)
        {   
            printf("%d is a wanshu\n",i);
            counter++;
        }
    }
    printf("There are %d wanshu(s) between 1and100\n",counter);
}
#5
小小小火柴2012-11-10 09:12
楼上正解
1