-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting arrays.cpp
More file actions
53 lines (46 loc) · 804 Bytes
/
sorting arrays.cpp
File metadata and controls
53 lines (46 loc) · 804 Bytes
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
// Sorting arrays.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <time.h>
using namespace std;
void sort(int[], int);
int _tmain(int argc, _TCHAR* argv[])
{
const int SIZE = 5;
int nums[SIZE];
int x;
char qFlag = 'n';
srand(time(NULL));
do {
for (int i = 0; i < SIZE; i++)
{
x = rand() % 100 + 1;
nums[i] = x;
cout << nums[i] << "\t";
}
sort(nums, SIZE);
cout << "quit?";
cin >> qFlag;
} while (qFlag != 'y' || qFlag != 'Y');
return 0;
}
void sort(int arr[], int SIZE)
{
int i = 0, x = 1;
int hold;
do{
if (arr[i] > arr[x])
{
hold = arr[i];
arr[i] = arr[x];
arr[x] = hold;
}
i++;
x++;
} while (x < SIZE);
for (int z = 0; z < SIZE; z++)
{
cout << arr[z] << "\t";
}
}