How To Find Prime Factor Of A Number in C++

This is the simple but logic building program in C++ about Prime Factor of a number. Prime factors of a positive number is the prime numbers that divide that integer exactly.

Source Code 

#include <iostream>
using namespace std;
void welcomeScrean(void);
void whosprime(long long x);

int main()
{
system ("color F0");

welcomeScrean();
long long r = 13195 ;
whosprime(r);

return 0;

}

void welcomeScrean(void){
cout<<"\a"
<<"\t*******************************************************"<<endl
<<"\t** **"<<endl
<<"\t** Welcome To **"<<endl
<<"\t** **"<<endl
<<"\t** Largest prime factor **"<<endl
<<"\t** **"<<endl
<<"\t** of 13195 **"<<endl
<<"\t** **"<<endl
<<"\t** Program **"<<endl
<<"\t** **"<<endl
<<"\t*******************************************************"<<endl
<<endl
<<endl;
}
void whosprime(long long x)
{
bool prime = true;

for(int loopOne = 1; loopOne <= x; loopOne++)
{
for(int loopTwo = 2; loopTwo <= x; loopTwo++)
{
if((loopOne != loopTwo) && (loopOne%loopTwo == 0))
{
prime = false;
break;
}
}

if(prime && x%loopOne == 0)
cout <<"\t "<< loopOne << endl;

prime = true;
}
}

Output of the Program

Find Prime Factor Of A Number in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment