-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayPrimeOrComposite.cpp
76 lines (57 loc) · 1.29 KB
/
ArrayPrimeOrComposite.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>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main(){
int elmo,count=0,search;
bool rt=false;
cout<<"Enter number of Elements: ";
cin>>elmo;
int arr[10];
for(int k=0; k<elmo; k++){//ENTER ELEMENTS
cout<<"Element["<<k<<"]"<<endl;
cin>>arr[k];
}
int val= arr[0];
int val1= arr[0];
int exp= arr[0];
cout<<"Enter number to be Search: ";
cin>>search;
for(int k=0; k<elmo; k++){
if(search!=arr[k]){
count++;
}
}
cout<<"Occurrences: "<<count<<endl;
cout<<endl;
for(int k=0; k<elmo; k++){//PRIME OR COMPOSITE
rt=false;
for(int i=2; i<=arr[k]/2; i++){
if(arr[k]%i!=0){
rt=true;
}
}
if(rt==false){
cout<<"Element["<<k<<"]: "<<arr[k]<<" is prime"<<endl;
}else{
cout<<"Element["<<k<<"]: "<<arr[k]<<" is composite"<<endl;
}
}
cout<<endl;
for(int k=0; k<elmo; k++){//HIGHEST OR LOWESt
if(arr[k]<val1){
val1=arr[k];
}
else if(arr[k]>val){
val=arr[k];
}
}
cout<<"The Highest is: "<<val<<endl;
cout<<"The Lowest is: "<<val1<<endl;
cout<<endl;
for(int k=0; k<elmo; k++){//EXPONENTATION
exp=pow(arr[k],k);
cout<<arr[k]<<" exponent "<<k<<" = "<<exp<<" "<<endl;
}
system("pause");
}