pa4_q5 anon

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

Info iconThis 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 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'
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background 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

This note was uploaded on 11/02/2009 for the course COSI 11a taught by Professor Dilillo during the Spring '09 term at Brandeis.

Page1 / 4

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

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online