-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_3.cpp
More file actions
51 lines (45 loc) · 724 Bytes
/
Problem_3.cpp
File metadata and controls
51 lines (45 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//EulerProblem3
#include<iostream>
#include<math.h>
// using standard namespace
using namespace std;
// function definition
int prime (long int x)
{
int a=0;
for (int j=2;j<=x/2;j++)
{
if (x%j==0)
{
a=1;
break;
}
}
return (a);
}
int factor(long int a)
{
long int x=1;
for (int i=2;i<a/2;i++)
{
if (a%i==0 )
{
x=a/i;
if (prime (x)==0)
{
break;
}
}
}
return x;
}
//End of Function
//Main function begins
int main ()
{
long int a;
cout<<"Enter the number "<<endl;
cin>>a;
cout<<"The largest prime factor is "<<factor(a);
}
//End Of Main