Answer to Question #235343 in C++ for Myname

Question #235343
A positive integer is entered through the keyboard; write a recursive function to obtain the
prime factors of that integer.
1
Expert's answer
2021-09-09T17:39:02-0400
#include<iostream>
using namespace std;
void P(int y);
int main()
{
    int y;
    cout<<"Enter an integer: ";
    cin>>y;
    cout<<"The Prime Factors of "<<y<<" are: ";
    P(y);
}
void P(int y)
{
    int m;
    for(m=2;m<=y;m++)
    {
        if(y%m==0)
        {
            cout<<" "<<m;
            P(y/m);
            break;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS