0

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;
}
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Duoas
-1

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

Votes + Comments
With that attitude, good riddance.
1

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.

Votes + Comments
Absolutely correct!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.