im suppose to Write a program that will be able to get the prime factors of the number input by the user. Make sure your program implements a recursive algorithm. also we are going to have the user input a number, and the program will find all prime numbers from 2 to that number. For an example, write all prime numbers from 2 to 3000. The last number should be 2999 in this case.
Example: 2,3,5,7,11,13,17.. etc.
my problem is when it find not a prime number it display number in stead of just displaying my message "is not a prime number"
#include <iostream>
#include <cmath>
usingnamespace std;
void get_primeFactors(int n)
{
int i;
double total = n*(n);
for (i = 2; i <= total; i++)
while (n % i == 0) {
cout << i << ", ";
get_primeFactors(n /= i);
return;
}
}
void get_primeNumbers(int a)
{
int s = 2;
double b = (a);
for (int i = s; i <= b; i++)
{
for (int j = 2; j <= i; j++)
{
if ((i%j==0)&&(i!=j)) //Condition for not prime
{
break;
}
elseif (j==i) //condition for Prime Numbers
{
get_primeFactors(i);
}
}
}
}
int main()
{
int n = 0;
int a = 0;
cout << "Enter a number : ";
cin >> n;
get_primeFactors(n);
cout << endl;
cout<<"Enter a another nummber : "<<endl;
cin>>a;
get_primeNumbers(a);
system("PAUSE");
return 0;
}