summaryrefslogtreecommitdiff
path: root/662/CH9/EX9.13
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /662/CH9/EX9.13
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '662/CH9/EX9.13')
-rwxr-xr-x662/CH9/EX9.13/example9_13.JPGbin0 -> 32101 bytes
-rwxr-xr-x662/CH9/EX9.13/example9_13.sci43
2 files changed, 43 insertions, 0 deletions
diff --git a/662/CH9/EX9.13/example9_13.JPG b/662/CH9/EX9.13/example9_13.JPG
new file mode 100755
index 000000000..7ea576cb0
--- /dev/null
+++ b/662/CH9/EX9.13/example9_13.JPG
Binary files differ
diff --git a/662/CH9/EX9.13/example9_13.sci b/662/CH9/EX9.13/example9_13.sci
new file mode 100755
index 000000000..6ea97ff18
--- /dev/null
+++ b/662/CH9/EX9.13/example9_13.sci
@@ -0,0 +1,43 @@
+ //Programming Example 9.13
+ //Reorder a 1 dimentional, integer array from smallest to largest
+
+function[] = main()
+ //read in a value for n
+ printf("\n How many numbers will be entered? ");
+ n = scanf("%d");
+ printf("\n");
+
+ //read in the list of numbers
+ for i =1:n
+ printf("i = %d x = ", i+1);
+ x(i) = scanf("%d");
+ end
+
+ //reorder all array elements
+ x=reorder(n,x);
+
+ //display the reordered list of numbers
+ printf("\n\nReordered List of numbers:\n\n");
+ for i=1:n
+ printf("i = %d x=%d\n", i, x(i));
+ end
+endfunction
+
+function[x] = reorder(n, x) //rearrange the list of numbers
+ for item=1:n-1
+ //find the smallest of all remaining elements
+ for i= item+1:n
+ if(x(i) < x(item))
+ //interchange two element
+ temp=x(item);
+ x(item)=x(i);
+ x(i)= temp;
+ end
+ end
+ end
+ return x;
+endfunction
+
+//calling main()
+funcprot(0);
+main(); \ No newline at end of file