lundi 1 octobre 2018

How to randomise an array in C

I am trying to develop some code that will take an array, randomise it and output a result in its hexadecimal form.

So far I have managed to create an array, store some numbers and output their hexadecimal form, but I am really stuck on how to create this random function. My knowledge of C is very minimal, so if anyone has any idea how I might create this random function. I would be very grateful.

I have listed my current code below:

#include <stdio.h>  // Library for functions like printf() and scanf()
#include <conio.h>

int main()
{
int i;

// Non printable ASCII characters
char  nonprint[30] = {1, 2, 3 , 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};

for(i = 0; i<30; i++)
{
    printf("%X ", nonprint[i]);   // Outputs all values declared in the array
}

return 0;
}

Output: 1 2 3 4 5 6 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F




Aucun commentaire:

Enregistrer un commentaire