summaryrefslogtreecommitdiff
path: root/3808/CH3/EX3.2/Ex3_2.sce
diff options
context:
space:
mode:
authorprashantsinalkar2017-10-10 12:27:19 +0530
committerprashantsinalkar2017-10-10 12:27:19 +0530
commit7f60ea012dd2524dae921a2a35adbf7ef21f2bb6 (patch)
treedbb9e3ddb5fc829e7c5c7e6be99b2c4ba356132c /3808/CH3/EX3.2/Ex3_2.sce
parentb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (diff)
downloadScilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.gz
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.tar.bz2
Scilab-TBC-Uploads-7f60ea012dd2524dae921a2a35adbf7ef21f2bb6.zip
initial commit / add all books
Diffstat (limited to '3808/CH3/EX3.2/Ex3_2.sce')
-rw-r--r--3808/CH3/EX3.2/Ex3_2.sce24
1 files changed, 24 insertions, 0 deletions
diff --git a/3808/CH3/EX3.2/Ex3_2.sce b/3808/CH3/EX3.2/Ex3_2.sce
new file mode 100644
index 000000000..23ee5ab2c
--- /dev/null
+++ b/3808/CH3/EX3.2/Ex3_2.sce
@@ -0,0 +1,24 @@
+//Chapter 03: Algorithms
+
+clc;
+clear;
+
+//Linear Search is also known as Sequential Search
+function []= linearsearch (a ,n , ie )
+i =1;
+j =0;
+for i =1: n
+if ( arr(i) == ie )
+printf ( "\nElement:%d found at position %d\n " ,ie , i ) ;
+j =1;
+end
+end
+if ( j ==0)
+disp ( "Element Not Found!") ;
+end
+endfunction
+
+arr =[1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22]
+l=length(arr)
+disp (arr , " Given array:" ) ;
+linearsearch (arr ,l ,19) //Note:input format for function is (array,length,element to be searched)