How to find prime factors of a number in c++?

﹥>﹥吖頭↗ 提交于 2019-12-02 02:41:36

Why You Don't Try

for(x=1;x<=number;x++)
{
    if(number%x==0 && isPrime(x))
    {
        f[a] = x;
        a++;
    }
}

.. ..

int isPrime(int x)
{

 for(int i=2;i<=x/2;i++)
 {
   if(x%i==0)
   return 0;
 }
 return 1;
 }

At least:

else if(f[st]%y!=0 && f[st!=y])

should be

else if(f[st]%y!=0 && f[st]!=y)

In the first way, you are trying to always access f[0] or f[1] by doing f[st!=y].

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!