Skip to content

Commit 52a3977

Browse files
Merge pull request PawanJaiswal08#56 from RohitChauhan13/master
Added Code to find prime factors
2 parents c5bbbc8 + 246fd18 commit 52a3977

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

prime_factor.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include <limits.h>
3+
using namespace std;
4+
5+
void printPrimeFactors(int n)
6+
{
7+
if(n <= 1)
8+
return;
9+
10+
for(int i=2; i*i<=n; i++)
11+
{
12+
while(n % i == 0)
13+
{
14+
cout<<i<<" ";
15+
16+
n = n / i;
17+
}
18+
}
19+
20+
if(n > 1)
21+
cout<<n<<" ";
22+
23+
cout<<endl;
24+
}
25+
26+
int main() {
27+
28+
int n = 450;
29+
30+
printPrimeFactors(n);
31+
32+
return 0;
33+
}

0 commit comments

Comments
 (0)