-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture9.cpp
More file actions
221 lines (159 loc) · 5.12 KB
/
Copy pathLecture9.cpp
File metadata and controls
221 lines (159 loc) · 5.12 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// #include<iostream>
// using namespace std;
// void reverse(int arr[], int n) {
// int start = 0;
// int end = n-1;
// while(start<=end) {
// swap(arr[start], arr[end]);
// start++;
// end--;
// }
// }
// // LINEAR SEARCH
// bool search(int arr[], int size, int key) {
// for( int i = 0; i<size; i++ ) {
// if( arr[i] == key) {
// return 1;
// }
// }
// return 0;
// }
// void sumofArray(int arr[], int size) {
// int sum = 0;
// cout<< " sum the array " << endl;
// //print the array
// for(int i =0; i<size; i++) {
// sum = sum + arr[i];
// }
// cout << sum << " ";
// cout<< " printing DONE " << endl;
// }
// void update(int arr[], int n) {
// cout << endl << "Inside the function" <<endl;
// //updating array's first element
// arr[0] = 120; // here array is updated in main also
// //printing the array
// for(int i=0; i<3; i++) {
// cout << arr[i] <<" ";
// } cout<<endl;
// cout << "Going back to main function" << endl;
// }
// int getMin(int num[], int size) {
// int mini = INT16_MAX;
// for(int i = 0; i<size; i++) {
// mini = min( mini, num[i]);
// //if(num[i] < min){
// // min = num[i];
// //}
// }
// //returning min value
// return mini;
// }
// int getMax(int num[], int size) {
// int maxi = INT16_MIN;
// for(int i = 0; i<size; i++) {
// maxi = max(maxi, num[i]);
// // if(num[i] > max){
// // max = num[i];
// // }
// }
// //returning max value
// return maxi;
// }
// // HOLD
// void printArray(int arr[], int size) {
// cout<< " printing the array " << endl;
// //print the array
// for(int i =0; i<size; i++) {
// cout << arr[i] << " ";
// }
// cout<<endl;
// }
//int main(){
// Question 1:
// We can initialize the array with any value by using the fill_n command
// Example:
// int arr[10];
// fill_n(arr,10,1);
// for (int i = 0; i <= 10; i++)
// {
// cout << ar[i] << endl;
// }
//declare
// int number[15];
// //accessing an array
// cout << "Value at 14 index " << number[14] << endl;
// //cout << "Value at 20 index " << number[20] << endl;
// //initialising an array
// int second[3] = {5, 7, 11};
// //accesing an element
// cout << "Value at 2 index " << second[2] << endl;
// int third[15] = {2,7};
// printArray(third, 15);
// int thirdSize = sizeof(third)/sizeof(int);
// cout<<" Size of Third is " << thirdSize <<endl; // it shows the complete length of the array a/c to (i)
// char ch[5] = {'a', 'b', 'c', 'r', 'p'};
// cout << ch[3] << endl;
// cout<< " printing the array " << endl;
// //print the array
// for(int i =0; i<5; i++) {
// cout << ch[i] << " ";
// }
// cout<< " printing DONE " << endl;
// double firstDouble[5];
// float firstFloat[6];
// bool firstBool[9];
// cout << endl << " Everything is Fine " << endl << endl
// int size;
// cin>>size;
// int num[100];
// //taking input in array
// for(int i = 0; i<size; i++) {
// cin >> num[i]; // array elemnets ko input krna
// }
// cout << " Maximum value is " << getMax(num, size) << endl;
// cout << " Minimum value is " << getMin(num, size) << endl;
// int arr[3] = {1,2,3};
// update(arr, 3); // here arr is address of actual update function
// //printing the array
// cout<< endl << "Printing in main function" << endl;
// for(int i=0; i<3; i++) {
// cout << arr[i] <<" ";
// }
// cout << endl;
// int size;
// cin>>size;
// int num[100];
// //taking input in array
// for(int i = 0; i<size; i++) {
// cin >> num[i]; // array elemnets ko input krna
// }
// sumofArray(num,size);
// LINEAR SEARCH
// int arr[10] = { 5, 7, -2, 10, 22, -2, 0, 5, 22, 1};
// cout <<" Enter the element to search for " << endl;
// int key;
// cin >> key;
// bool found = search(arr, 10, key);
// if( found ) {
// cout <<" Key is present "<< endl;
// }
// else{
// cout <<" Key is absent " << endl;
// }
// REVERSE OF AN ARRAY
// int size;
// cin>>size;
// int arr[10] = { 5, 7, -2, 10, 22, -2, 0, 5, 22, 1};
// for(int i = size-1; i>=1; i--){
// cout<<arr[i]<<" ";
// }
// // REVERSE OF AN ARRAY
// int arr[6] = {1,4,0,5,-2,15};
// int brr[5] = {2,6,3,9,4};
// reverse(arr, 6);
// reverse(brr, 5);
// printArray(arr, 6);
// printArray(brr, 5);
// return 0;
// }