-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathprimesort.cpp
76 lines (59 loc) · 1.82 KB
/
primesort.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
using namespace std;
int main()
{
cout<<" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<" SORTING AN ARRAY INTO PRIME AND NON-PRIME \n";
cout<<" `````````````````````````````````````````````````````````````````````````\n\n\n";
int n,num[5000],temp_a[5000],temp_b[5000],q=0,k=0;
cout<<"Enter the size of array :- ";
while(!(cin>>n)|| (n<0))
{
cin.clear();
cin.ignore(100,'\n');
cout<<"INVALID INPUT. ENTER AGAIN:";
}
cout<<"Enter the elements of array :-- \n";
for(int i=0;i<n;i++)
{
cin>>num[i];
}
cout<<" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n\n";
cout<<"The Array you entered is:- [ ";
for(int x=0;x<n;x++)
{
cout<<num[x]<<" ";
}
cout<<"]\n\n\n";
for(int i=0;i<n;i++)
{
int fact=0;
for(int j=1;j<=num[i];j++)
{
if(num[i]%j==0)
{
fact++;
}
}
if(fact==2)
{
temp_a[k++]=num[i];
}
else
{
temp_b[q++]=num[i];
}
}
cout<<" ==============================================================================\n\n";
cout<<" PRIME ELEMENTS ARE :-- ";
for(int i=0;i<k;i++)
{
cout<<temp_a[i]<<" ";
}
cout<<"\n NON-PRIME ELEMENTS ARE :-- ";
for(int i=0;i<q;i++)
{
cout<<temp_b[i]<<" ";
}
cout<<"\n ==============================================================================\n\n";
}