{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

labprog9-2010

labprog9-2010 - defined as the average of the two middle...

This preview shows page 1. Sign up to view the full content.

Swinburne University of Technology Faculty of Engineering and Industrial Sciences HES1300 Robotics & Mechatronics Project 1 Laboratory assignment 9: Your task for this session is as follows: 1. Carefully study the following program and make sure you fully understand how it works. Pay particular attention to the way that an array has been passed to a function (two-way communication for arrays – discuss the issue with your lab tutor if you're not sure!). 2. Using the provided sort function, write a new function called myMedian which takes an array of integers of any size and the size of the array as inputs and returns its median. For this exercise, if there were odd number of elements in the array, then the median would be the middle number in the sorted array. However, if the number of elements were even, then the median would be
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: defined as the average of the two middle numbers (after sorting). 3. Write comments for all the functions (including main) in your program. #include <stdio.h> #include <stdlib.h> #include <time.h> void sort(int mynum, int size) { int pass, indx, hold; for(pass = 0; pass < size - 1 ; pass++) { for (indx = 0; indx < size - pass - 1; indx++) { if( mynum[indx] > mynum[indx + 1] ) { hold = mynum[indx]; mynum[indx] = mynum[indx + 1]; mynum[indx + 1] = hold; } } } } int main () { int i,mynum[10], mycopy[10]; srand((unsigned)time(NULL)); for(i = 0; i < 10; i++) { mynum[i] = rand(); mycopy[i] = mynum[i]; } sort(mynum, 10); printf("original numbers sorted numbers\n"); for(i = 0; i < 10; i++) { printf("%10d %17d \n",mycopy[i],mynum[i]); } return(0); }...
View Full Document

• Three '10
• lauren
• Sorting, #include, Swinburne University of Technology, Faculty of Engineering and Industrial Sciences, indx < size

{[ snackBarMessage ]}