diff options
Diffstat (limited to '659/CH9/EX9.6/exm9_6.sci')
-rwxr-xr-x | 659/CH9/EX9.6/exm9_6.sci | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/659/CH9/EX9.6/exm9_6.sci b/659/CH9/EX9.6/exm9_6.sci new file mode 100755 index 000000000..dc947e421 --- /dev/null +++ b/659/CH9/EX9.6/exm9_6.sci @@ -0,0 +1,20 @@ +// Example 9.6
+//Write a program that uses a function to sort an array of integers.
+funcprot(0);
+function[x]=sort(m,x) //Passing an array i.e. marks to function sort()
+ for i=1:m // i repesents number of passes
+ for j=2:m-i+1 // j represents number of comperision in each pass
+ if(x(j-1)>=x(j)) then
+ t=x(j-1);
+ x(j-1)=x(j);
+ x(j)=t;
+ end
+ end
+ end
+endfunction
+marks=int16([40,90,73,81,35]); //creating an array named marks of 5 integers
+disp("Marks before sorting");
+disp(marks);
+x=sort(5,marks); //calling sort() function
+disp("Marks after sorting");
+disp(x);
\ No newline at end of file |