-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIndingSmallestLargestInteger.cpp
74 lines (51 loc) · 1.38 KB
/
FIndingSmallestLargestInteger.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
#include<iostream>
using namespace std;
// A program to find the largest and smallest integer from a user inputted list of integer.
// We will use the technique of mergesorting to sort the list of integer. The first element of the sorted list will give the smallest integer and the last element will give the largest integer.
void swap (int *x,int *y) {
int temp = *x;
*x=*y;
*y=temp;
}
void sort(int A [], int sizeofarray) {
int i = 0;
int h = sizeofarray-1;
int mid = (i + h)/2;
int l = 0;
int B[h];
for(i=0; i <= h;i++) {
for(int j=0; j<=h-i-1; j++) {
if(A[j] >= A[j+1]) {
swap(&A[j], &A[j+1]);
}
}
}
for(int i = 0; i<=h; i++) {
cout << A[i];
cout << '\n';
}
int largest = A[h];
int smallest = A[0];
cout << "Largest integer: " << largest << endl;
cout << "Smallest integer: " << smallest << endl;
}
//cout << "Largest integer: " << largest << endl;
//cout << "Smallest integer: " << smallest << endl;
int main () {
const int sizeofarray = 100;
int counter=0;
int A[counter];
for (int i=0; i<sizeofarray-1; i++) {
cout << " Enter Array element: " << endl;
cin >> A[i];
counter++;
cout<< "Counter " << counter;
if(A[i]== -99)
//counter--;
break;
}
//sizeof(arr[7])/sizeof(arr[0]);
//cout << "Size of array " << sizeofarray << endl;
cout << counter;
//sort(A, counter);
};