File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <iostream>
2
+ using namespace std;
3
+
4
+ int main()
5
+ {
6
+ // Creating the array and nth value
7
+ int n;
8
+ cout << "Enter nth number of values: ";
9
+ cin >> n;
10
+ cout << "Enter the values:" << endl;
11
+
12
+ // Entering values into the array
13
+ int* arr = new int[n];
14
+ for (int i = 0; i < n; i++){
15
+ cin >> arr[i];
16
+ }
17
+
18
+ // Maximum and Minimum values
19
+ int min = arr[0];
20
+ int max = arr[0];
21
+
22
+ // For-loop calculates maximum and minimum values of the array
23
+ for (int i = 1; i < n; i++){
24
+ if (arr[i] > max){
25
+ max = arr[i];
26
+ }
27
+ if (arr[i] < min) {
28
+ min = arr[i];
29
+ }
30
+ }
31
+
32
+ // Display maximum and minimum values
33
+ cout << "\nMax: "<< max << endl;
34
+ cout << "\nMin: " << min << endl;
35
+
36
+ // Display the span of the array
37
+ int span = max - min;
38
+ cout << "\nSpan: " << span << endl;
39
+ }
You can’t perform that action at this time.
0 commit comments