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
|
#include <iostream>
using namespace std;
void display_array(int x[], int size);
void min_max(int x[], int size);
void insertion_sort(int arr[], int size);
int main()
{
int i, size=10, pers[10];
for (i = 0; i < size; i++)
{
cout << "How many pancakes did person " << (i + 1) << " eat?" << endl;
cin >> pers[i];
}
min_max(pers,size);
insertion_sort(pers, size);
system("pause");
return 0;
}
void display_array(int x[], int size)
{
for (int i = 0; i < size; i++)
{
cout << x[i] << " ";
}
}
void min_max(int x[], int size)
{
int maxPers=1, minPers=1;
int min = x[0];
int max = x[0];
for (int i = 0; i < size; i++)
{
if (x[i]>max)
{
max = x[i];
maxPers = i + 1;
}
if (x[i] < min)
{
min = x[i];
minPers = i + 1;
}
}
cout << "Person " << maxPers << " ate the most pancakes! " << ": " << max << endl;
cout << "Person " << minPers << " ate the least amount of pancakes" << ": " << min << endl;
}
void insertion_sort(int arr[], int size)
{
int j, temp,i=0;
for (i = 0; i < size;i++)
{
j = i;
while (j>0 && arr[j - 1] > arr[j])
{
temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
j--;
}
}
display_array(arr, size);
}
|