Question: The following C program named sort.c is a program that can sort an array of values in ascending order. However, some parts of the code

  1. The following C program named sort.c is a program that can sort an array of values in ascending order. However, some parts of the code (highlighted in yellow color below) are missing.

  1. (1)___________
  2. // swap the value between input a and b
  3. void swap(int *a, int *b)
  4. {
  5. int temp = (2)__________;
  6. *a = *b;
  7. *b = temp;
  8. }
  9. // sort the input values in order from smallest to largest
  10. void sort(int values[], int n)
  11. {
  12. int i;
  13. for (i = 0; (3)________; i++)
  14. {
  15. (4)____________;
  16. for (j = 0; j< n-i-j; (5)___________)
  17. {
  18. int *a = &values[j];
  19. int *b = &values[j + 1];
  20. if ((6)___________)
  21. {
  22. swap(a, b);
  23. }
  24. }
  25. }
  26. }
  27. // display the input array of values in a line
  28. void print_array((7)________________)
  29. {
  30. int i;
  31. for((8)_________; i < n; i++)
  32. {
  33. printf((9)___________, values[i]);
  34. }
  35. printf(" ");
  36. }
  37. // main function to execute
  38. (10)_______ main ()
  39. {
  40. int values[] = {5, 3, 6, 4, 2, 1};
  41. int n = sizeof(values) / sizeof(values[0]);
  42. printf("Before sorting: ");
  43. (11)________________
  44. (12)________________ // sort the values
  45. printf("After sorting: ");
  46. print_array(values, n);
  47. }

The following figure shows an example of the results when running the complete version of the above C program:

Please read and try to understand the program code, then fill in the missing blankets with appropriate short statements to make the program work correctly.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!