summaryrefslogtreecommitdiff
path: root/659/CH8/EX8.9
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /659/CH8/EX8.9
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 '659/CH8/EX8.9')
-rwxr-xr-x659/CH8/EX8.9/exm8_9.sce31
-rwxr-xr-x659/CH8/EX8.9/exm8_9_outout.PNGbin0 -> 12510 bytes
2 files changed, 31 insertions, 0 deletions
diff --git a/659/CH8/EX8.9/exm8_9.sce b/659/CH8/EX8.9/exm8_9.sce
new file mode 100755
index 000000000..d65e65504
--- /dev/null
+++ b/659/CH8/EX8.9/exm8_9.sce
@@ -0,0 +1,31 @@
+// Example 8.9
+//Write a program that would sort a list of names in alphabetical order.
+
+ITEMS=5;
+//Reading the list
+printf("Enter names of %d items\n",ITEMS);
+i=1;
+while(i<=ITEMS)
+ string1(i)=scanf("%s");
+ i=i+1;
+end
+//Sorting begins
+for i=1:ITEMS //Outer loop begins
+ for j=2:ITEMS-i+1 //Inner loop begins
+ k=strcmp(string1(j-1),string1(j))
+ if(k>0) then
+ //Compute length and Exchange of contents
+ l1=length(string1(j-1));
+ l2=length(string1(j));
+ dummy=strncpy(string1(j-1),l1);
+ string1(j-1)=strncpy(string1(j),l2);
+ l3=length(dummy);
+ string1(j)=strncpy(dummy,l3);
+ end
+ end //Inner loop ends
+end //Outer loop ends
+//Sorting completed
+disp("Alphabetical list");
+for i=1:ITEMS
+ printf("%s\n",string1(i));
+end
diff --git a/659/CH8/EX8.9/exm8_9_outout.PNG b/659/CH8/EX8.9/exm8_9_outout.PNG
new file mode 100755
index 000000000..f1d63a4ad
--- /dev/null
+++ b/659/CH8/EX8.9/exm8_9_outout.PNG
Binary files differ