This works and shows the factors or tells if the number is a prime number but doesn't show ODD factors please help!! I need to turn this tomorrow

#include <iostream>
using namespace std; 	
int prime(int num);
int main()
{
int num;
cout<<"Enter number: ";
cin>>num;
if(prime(num)==1)
cout<<"The number is prime";
else
{ 
cout<<"The number is not prime, factors are\n1\n";
if( num%2==0)
 for(int j=2;j<num;j+=2)
 {
 if(num%j==0)
 cout<<j<<endl;
 }
 for( int n=num;n<=num;n/=2)
 {
 if(num%n==0)
 cout<<n<<endl;
 }
 for(int m=3;m<num;m+=3)
 {
 if(num%m==0)
 cout<<m<<endl;
 }
}
}
int prime(int num)
{
    if(num <= 1)
    {
         return false;
    }
    if(num == 2)
    {
         return true;
    }
    if ( num%2 == 0)
    {
       return false;
    }
    
    for (int n=3;n*n <= num;n+=2)
    {   if (num%n == 0)
           return false;
    }
    return true;
}

Recommended Answers

All 2 Replies

I solved it my self and no one here helped(or even replied) so I'm NEVER coming here back EVER again.

commented: With that attitude, good riddance. -3

You're kidding, right? You demand us to help you in less than two hours? Go get a job and see how long people put up with you.

Since you fixed it yourself I won't bother giving you my answer.

commented: Absolutely correct! +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.