c语言大神进 任何一个自然数的约数中都有1和它本身,我们把小于它本身的因数叫做这个自然

2024-11-20 14:35:11
推荐回答(4个)
回答1:

你的错误:
for(i=m;i<=n;i++)
        {
          for(d=1;d            {
              g=i%d;
              if(g==0)
                a[d]=i/d;//a[d]=i/d  错误  比如i=6  a[1]=6/1=6  a[2]=6/2=3      
              else
                continue;
       差扒     }
             for(d=1;d            {
              s=0;
              s=s+d+a[d];//错误                                                 
            }


/////                                                                                                                                           
#include
int main()
{
  int n,m,a[100],i,s,d,g,sum=0;
  printf("请输入m,n的值");
  scanf("%d %d",&m,&n);
  if((n==0&&m==0)||(m>n))
    printf("error");
  if((n!=0||m!=0)&&(m<=n))
    {
      for(i=m;i<=n;i++)
        {
          for(d=1;d            {
              g=i%d;
              if(g==0)
                {
                  //    a[d]=d;/////             高庆肆                                                                                                                                  
                  sum+=d;
                }
              else
                continue;
            }
          //      for(d=1;d          //        {                                                                                                                                                              
          //  s=0;                                                                                                                                                                 
          //  s=s+d+a[d];                                                                                                                                                          
          //}                                                                                                                                                                      

          if(i==sum)//                                                                                                                                                             
            printf("%d\n ",i);
          //      else                                                                                                                                                             
          // printf("no\n");//                                                                                                                                                     
          sum=0;//                                                        戚轿                                                                                                         
        }
    }
}

回答2:

#include
void main()
{
int n,m,i,s,d;
printf("请输入m,n的值:");
scanf("%d %d",&m,&n);
while((n==0&&m==0)||(m>n))
{
printf("差核error\n");
printf("请碰拍输入m,n的值虚吵掘:");
scanf("%d %d",&m,&n);
}
if((n!=0||m!=0)&&(m<=n))
{
for(i=m;i<=n;i++)
{
s=0;
for(d=1;d {
if(!(i%d))
s += d;
}
if(i==s)
printf("%d\n",i);
}
}
}

回答3:

3 2 1=6 3+2+1

回答4:

你写的太乱,我写了一个则历程序,你看看,不懂再问

#include <孙伍搜stdio.h>
int main(int argc, char *argv[])
{
int m,n;
int i,j,k=0;
printf("输入m,n的值(mscanf("%d%d",&m,&n);
if((m<=0 || n<=0)|| (m>n))
{
printf("error\n"橘晌);
return 0;
}
for(i=m;i<=n;i++)
{
for(j=1;j {
if(i%j == 0)
k += j;
}
i f(k==i)
printf("%d是完数\n",k);
k = 0;
}
return 0;
}