-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_array.cpp
More file actions
67 lines (65 loc) · 1.34 KB
/
3_array.cpp
File metadata and controls
67 lines (65 loc) · 1.34 KB
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
//
// Created by Varsha on 21-03-2023.
//
#include <iostream>
using namespace std;
class array{
private:
static int arr[100],n;
int i,sum=0;
public:
void init(){
cout<<"Enter the number of elements in the array:";
cin>>n;
cout<<"Enter the elements of the array:";
for(i=0;i<n;i++){
cin>>arr[i];
}
}
void average(){
for(i=0;i<n;i++){
sum+=arr[i];
}
cout<<"The average of the array is: "<<sum/n<<endl;
}
void multiply(){
int multiplier;
cout<<"Enter the multiplier:";
cin>>multiplier;
for(i=0;i<n;i++){
arr[i]*=multiplier;
}
cout<<"The array is: ";
}
void sort(){
int temp;
for(i=0;i<n;i++){
for(int j=0;j<n-i-1;j++){
if(arr[j]>arr[j+1]){
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
cout<<"The array after sorting is: ";
}
void display(){
for(i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
};
int array::arr[100]={0};
int array::n=0;
int main(){
array a1,a2,a3,a4;
a1.init();
a2.average();
a3.multiply();
a3.display();
a4.sort();
a4.display();
return 0;
}