Advertisement
Guest User

skeleton code ex 7-6

a guest
Aug 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MAXLEN 1000 /* our limit on how many integers will go into an array */
  5.  
  6. /* function declarations go here */
  7. void selection_sort(int A[], int n);
  8. void print_int_array(int A[], int n);
  9.  
  10. int
  11. main() {
  12.     int A[MAXLEN];
  13.     int val; /* val is going to be the variable that scanf reads values into */
  14.     int n; /* n is the number of elements read into the array */
  15.     printf("Enter up to 1000 numbers: \n");
  16.     while (scanf("%d",&val) == 1) {
  17.         A[n] = val;
  18.         n++;
  19.     }
  20.  
  21.     /* call function on the array here */
  22.     printf("Sorting ...\n");
  23.     selection_sort(A, n);
  24.     print_int_array(A, n); /* this will print the sorted array :o */
  25.  
  26.     return 0;
  27. }
  28.  
  29.  
  30. void print_int_array(int A[], int n) {
  31.     int i;
  32.     for (i=0; i<n; i++) {
  33.         printf("%d ", A[i]);
  34.     }
  35.     printf("\n");
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement