BIL104E_w7 - BIL104E INTRODUCTION TO SCIENTIFIC AND...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
BIL104E INTRODUCTION TO SCIENTIFIC AND ENGINEERING COMPUTING (C) WEEK – 7
Background image of page 1

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

View Full DocumentRight Arrow Icon
Sorting Arrays Sorting array elements from Smaller to bigger (increasing order) Original: 3 4 2 6 7 Sorted: 2 3 4 6 7 Bigger to smaller (decreasing order) Original : 3 4 2 6 7 Sorted: 7 6 4 3 2
Background image of page 2
Increasing order: for ( pass = 1; pass < 8; pass++ ) { for ( i = 0; i < 7; i++ ) { if ( a[ i ] > a[ i + 1 ] ) { hold = a[ i ]; a[ i ] = a[ i + 1]; a[ i + 1 ] =hold; } } } a = {2,6,8,3,9,5,10,7} i=0 a[0]=2 and a[1]=6 a[0]<a[1] Skip ------------------------------------------------------------- i=1 a[1]=6 and a[2]=8 a[1]<a[2] Skip ------------------------------------------------------------- i = 2 a[2] =8 and a[3] = 3 a[2] > a[3] hold = a[2]= 8 a[2] = a[3] = 3 a[3] = hold = 8 a[2] = 3, a[3] = 8 a={2,6,3,8,9,5,10,7} ------------------------------------------------------------- i = 3 a[3] = 8 and a[4] = 9 a[3]<a[4] Skip ------------------------------------------------------------- i = 4 a[4] = 9 and a[5] = 5 a[3] >a[4] hold = a[4]= 9 a[4] = a[5] = 5 a[5] = hold = 9 a[4] = 5, a[5] = 9 a={2,6,3,8,5,9,10,7} a = {2,3,5,6,7,8,9,10} AFTER SEVERAL STEPS In decreasing order use ( a[ i ] < a[ i + 1 ] ) instead of ( a[ i ] > a[ i + 1 ] )
Background image of page 3

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

View Full DocumentRight Arrow Icon
Application-I Sort the following array in both increased and decreased order A[N] = {11,42,4,3,8,12,9,34,25,10} Define N by using #define Use functions for Increased order Decreased order Call functions in main function and print the original, increased ordered and decreased ordered arrays
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/22/2010 for the course BIL 104 taught by Professor Abc during the Fall '09 term at Istanbul Technical University.

Page1 / 18

BIL104E_w7 - BIL104E INTRODUCTION TO SCIENTIFIC AND...

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

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