Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define NMAX 10
- int arr[NMAX];
- void swapInts(int *a, int *b) {
- int aux = *a;
- *a = *b;
- *b = aux;
- }
- int randInRange(int low, int high) {
- return rand() % (high - low + 1) + low;
- }
- void randShuffle(int arr[], int low, int high) {
- for (int i = low; i <= high; i++) {
- int j = randInRange(low, high);
- swapInts(arr + i, arr + j);
- }
- }
- void printArray(int arr[], int n) {
- for (int i = 0; i < n; i++) {
- printf("%d ", arr[i]);
- }
- puts("");//*/
- }
- int main(void) {
- srand(time(NULL));
- for (int i = 0; i < NMAX; i++) {
- arr[i] = i + 1;
- }
- printArray(arr, NMAX);
- randShuffle(arr, 4, 8);
- printArray(arr, NMAX);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement