pa4_q5 anon

# pa4_q5 anon - smallest=j/swap time temp = a[i a[i =...

This preview shows pages 1–4. Sign up to view the full content.

Sheet1 Page 1 /*This is a different sorting algorithm, which finds the smallest number in an array, and swaps it with the first item in the array. It then repeats this action, starting with the second position of the array and the second smallest number, until it reaches the end of the array. Known bugs: none 1 Nov*/ #include <stdio.h> int main (void) { int a[10] int i, j, temp int smallest printf ("Please enter the 10 integers of your array: ") for (i=0 i<10 scanf ("%d", &a[i]) for (i=0 i<10 { smallest = i for (j=i+1 j<10 { if (a[j] < a[smallest])//if next number is smaller, it is new 'smallest'

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { smallest=j } } //swap time temp = a[i] a[i] = a[smallest] a[smallest] =temp } //loop to show new array values for (i=0 i&amp;lt;10 { printf(&amp;quot;a[%d] = %d\n&amp;quot;, i, a[i]) Sheet1 Page 2 } /*for(i=0, . ..) small=i for(j=i+1,. ..) if (a[j]&amp;lt;a[smallest] small=j small, j, i is locations temp is value know when i'm applying location and value*/ return 0 } Sheet1 Page 3 i++) i++)//controls which space we want the value for j++)//looking for the place i++) Sheet1 Page 4...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern