[求助],“找出一千以内因子最多的数”
请教各位,“找出一千以内因子最多的数”要怎么编。谢谢
#include <iostream>
using namespace std;
void main()
{
int b=0,temp=0,c;
for(int n=0;n<1000;n++)
{
int a=0;
for(int m=2;m<n;m++)
if(n%m==0)
a++;
if(a>temp)
{
temp=a;
c=n;
}
}
cout<<c<<endl;
}
判断的是因子,不是判断素数,怎么能那样呢
谢谢,帮忙看看这样写有什么错
#include<iostream>
using namespace std;
int fun1(int m)
{
int a,i;
for(i=1;i<=m;i++)
{
if(m%i==0) a++;
}
return (a);
}
void main()
{
int n,k,temp=0;
for(n=2;n<=1000;n++)
{
k= fun1( n);
if (k>temp) temp=k;
}
cout<<temp<<endl;
}
int fun1(int m)
{
int a=0,i; //a必须初始化
for(i=1;i<=m;i++)
{
if(m%i==0) a++;
}
return (a);
}
void main()
{
int n,k,temp=0;
for(n=2;n<=1000;n++)
{
k= fun1( n);
if (k>temp) temp=k;
}
cout<<temp<<endl;
}
你这输出的是最多因子的数目,不是有最多因子的数