-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrimeFactors.cpp
45 lines (45 loc) · 945 Bytes
/
PrimeFactors.cpp
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
#include<iostream>
using namespace std;
void prime(int x)
{
static int i=2;
if(i<=x)
{
if(x%i==0)
{
cout<<i<<" ";
x=x/i;
}
else
{
i++;
}
prime(x);
}
}
int main()
{
int n,choice;
do
{
cout<<"\nMake a choice: \n1. Calculate Prime Factor\n2. Exit\n";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter the number you want to find the factors of: ";
cin>>n;
cout<<"The prime factors of "<<n<<" are: "<<endl;
prime(n);
break;
}
case 2:
cout<<"Have a nice time ahead! Bye!"<<endl;
break;
default:
cout<<"Invalid input! Try again!";
}
}while(choice!=2);
return 0;
}