• Sign Up
• Login
• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

# Untitled

a guest Jan 11th, 2017 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <time.h>
3. #include <random>
4.
5. using namespace std;
6.
7. void bubbleSort(int* numbers, int length) {
8.     int temp = 0;
9.     for (int y = 0; y < length; y++) {
10.         for (int x = 0; x < length - y; x++) {
11.             if (numbers[x] > numbers[x + 1]) {
12.                 int temp = numbers[x];
13.                 numbers[x] = numbers[x + 1];
14.                 numbers[x + 1] = temp;
15.             }
16.         }
17.     }
18. }
19.
20. int main() {
21.     const int SIZE = 600;
22.     int numbers[SIZE];
23.
24.     default_random_engine engine(time(0));
25.     uniform_int_distribution<int> random(1, 100);
26.
27.     for (int x = 0; x < SIZE; x++)
28.         numbers[x] = random(engine);
29.
30.
31.     int newNumbers[SIZE];
32.
33.     for (int x = 0; x < SIZE; x++)
34.         newNumbers[x] = numbers[x];
35.
36.     int total = 0;
37.     int min = 100;
38.     int max = 1;
39.
40.     for (int x = 0; x < SIZE; x++) {
41.         if (numbers[x] > max) max = numbers[x];
42.         if (numbers[x] < min) min = numbers[x];
43.         total += numbers[x];
44.     }
45.
46.     float average = (float)total / SIZE;
47.
48.     cout << "Minimum: " << min << endl;
49.     cout << "Maximum: " << max << endl;
50.     cout << "Average: " << average << endl;
51.
52.     cout << "How many of: " << endl;
53.     int answer;
54.     cin >> answer;
55.     cin.get();
56.
57.     int instances = 0;
58.     for (int x = 0; x < SIZE; x++)
59.         if (numbers[x] == answer)
60.             instances++;
61.
62.     cout << instances << endl;
63.
64.     int instancesOf[100];
65.
66.     for (int x = 0; x < 100; x++)
67.         instancesOf[x] = 0;
68.
69.     for (int x = 0; x < 600; x++)
70.         instancesOf[numbers[x] - 1]++;
71.
72.     instances = 0;
73.     for (int x = 0; x < 100; x++)
74.         if (instancesOf[x] > instances)
75.             instances = x;
76.
77.     cout << "Most instances: " << instances << endl;
78.
79.     bubbleSort(numbers, SIZE - 1);
80.
81.     int i = 0;
82.     for (int x = 0; x < SIZE; x++) {
83.         if (numbers[x] > i) {
84.             i++;
85.             cout << endl;
86.         }
87.         cout << numbers[x] << " ";
88.     }
89.     cout << endl;
90.
91.     return 0;
92. }
RAW Paste Data
Top