The question to my homework is:
1. Trace the following C program. For each iteration of the outer loop, illustrate the array.
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- int main()
- {
- int num[10] = {97, 25, 15, 77, 38, 10, 5, 27, 50, 1};
- int x, y, z, temp;
- /* start of outer loop */
- for (x = 0; x < 9; x++)
- {
- temp = num[x];
- /* start of inner loop */
- for (y = x + 1; y < 10; y++)
- {
- if (temp > num[y])
- {
- temp = num[y];
- z = y;
- }
- } /*end of inner loop */
- num[z] = num[x];
- num[x] = temp;
- } /*end of outer loop */
- return 0;
- }
Please help me solve this...
Show me some explanations and illustrations if possible. thanks!