Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define SIZE 40
- int main()
- {
- int v[SIZE];
- int i, j, tmp;
- /* Initialize array to random positive integers, mod 256 */
- for (i = 0; i < SIZE; i++) {
- v[i] = rand() & 0xFF;
- printf(“v[%-d]: %d\n”, i, v[i]);
- }
- /* Sort the array using an insertion sort */
- for (i = 1; i < SIZE; i++) {
- tmp = v[i];
- for (j = i; j > 0 && tmp < v[j-1]; j--)
- v[j] = v[j-1];
- v[j] = tmp;
- }
- /* Print out the sorted array */
- printf(“\nSorted array:\n”);
- for (i = 0; i < SIZE; i++)
- printf(“v[%-d]: %d\n”, i, v[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement