summaryrefslogtreecommitdiff
path: root/260/CH8/EX8.1/8_1.sce
blob: f604a0841f1082246b694b9a77a007bb2f9e9137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Eg-8.1
//pg-365


clear
clc

A = [-2 1 4 3 1.5];
//printf('The given array is \n')

exec('swap.sci')

//disp(A)

n = length(A);

printf('The given array is \n')

disp(A)

for(i=1:n)
    
    for(i=1:n-1)
        if(A(i) > A(i+1))
        [A(i),A(i+1)] = swap(A(i),A(i+1))
        end
    end
end

printf('\n\nThe array after arranging in ascending order using bubble-sort algorithm is\n')
disp(A)