Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

Students also viewed these Databases questions