diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /662/CH9/EX9.13 | |
download | Scilab-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-x | 662/CH9/EX9.13/example9_13.JPG | bin | 0 -> 32101 bytes | |||
-rwxr-xr-x | 662/CH9/EX9.13/example9_13.sci | 43 |
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 Binary files differnew file mode 100755 index 000000000..7ea576cb0 --- /dev/null +++ b/662/CH9/EX9.13/example9_13.JPG 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 |