Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* AUTH: Kevin Strijbos
- DATE: 17/01/2012
- DESCR: includes 2 functions that combine arrays
- */
- #include <stdio.h>
- #define MAX_LENGTH 3
- void initializeArray (int numbers[], int *pointers[]);
- void initializeMinima (int numbers[], int pointers[]);
- int main (void)
- {
- int numbers[MAX_LENGTH];
- int *pointers[MAX_LENGTH];
- int counter;
- for (counter = 0; counter < MAX_LENGTH ;counter++)
- {
- printf("Geef een getal:\t\n");
- scanf("%d", &numbers[counter]);
- }
- initializeArray(numbers,pointers);
- for (counter = 0; counter < MAX_LENGTH ;counter++)
- printf("Element %d:\t%d\n", counter, *pointers[counter]);
- initializeMinima(numbers, pointers);
- for (counter = 0; counter < MAX_LENGTH ;counter++)
- printf("Element %d:\t%d\n", counter, *pointers[counter]);
- return 0;
- }
- void initializeArray (int numbers[], int pointers[])
- {
- int counter;
- for (counter = 0; counter < MAX_LENGTH ;counter++)
- pointers[counter] = &numbers[counter];
- }
- void initializeMinima (int numbers[], int pointers[])
- {
- for (counter = 0; counter < MAX_LENGTH - 1 ;counter++)
- {
- minima = numbers[counter];
- index = counter;
- for (smallCounter = counter + 1; smallCounter < MAX_LENGT ;smallCounter++)
- {
- if (numbers[smallCounter] < minima)
- {
- minima = numbers[smallCounter];
- index = smallCounter;
- }
- }
- /* swapping minima */
- temp = pointers[counter];
- pointers[counter] = pointers[index];
- pointers[index] = temp;
- }
- }
Add Comment
Please, Sign In to add comment