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;
}
}
0 comments:
Post a Comment