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

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

View Full Document Right Arrow Icon
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'
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
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

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern