-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathArray_Operations.cpp
More file actions
48 lines (42 loc) · 863 Bytes
/
Array_Operations.cpp
File metadata and controls
48 lines (42 loc) · 863 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
//Functions for searching, shorting, and manupulating
#include<iostream>
#define N=10
using namespace std;
void search(int *ptr);
void sort(int *ptr);
void left_shift(int *ptr);
void right_shift(int *ptr);
double average(int *ptr);
int main()
{
int array[N]={6,7,8,4,3,2,1,9,8,10};
int *ptr=array;
int s;
cin>>s;
select(s)
{
case 1: search(ptr);break;
case 2: sort(ptr);break;
case 3: left_shift(ptr);break;
case 4: right_shift(ptr);break;
case 5: average(ptr);break;
default: break;
}
for(int i=0;i<N;i++)
{
cout<array[i];
}
return 0;
}
//Write the functions here, one by one.
double average(int *ptr){
double avg = 0;
int sum = 0;
int n = N;
while(n--){
sum += *ptr;
ptr++;
}
avg = (double)sum/N;
return avg;
}