From b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b Mon Sep 17 00:00:00 2001 From: priyanka Date: Wed, 24 Jun 2015 15:03:17 +0530 Subject: initial commit / add all books --- 37/CH8/EX8.2/s2.sci | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 37/CH8/EX8.2/s2.sci (limited to '37/CH8/EX8.2') diff --git a/37/CH8/EX8.2/s2.sci b/37/CH8/EX8.2/s2.sci new file mode 100755 index 000000000..6c93fab59 --- /dev/null +++ b/37/CH8/EX8.2/s2.sci @@ -0,0 +1,20 @@ +//Finding The Number Of Paths From One Vertex To Another Of A Given Length + +function[b]=path(k,n,adj,i,j) + b=0; + if(k==1) + b=adj((i-1)*n+j); + else + for c=1:n + if(adj((i-1)*n+c)==1) + b=b+path(k-1,n,adj,c,j); + end + end + end + printf("Number of paths from vertex %d to %d of length %d are %d",i,j,k,b); + return b; +endfunction +//Calling Routine: +n=3; +adj=[0 1 1 0 0 1 0 0 0] +b=path(1,n,adj,1,3) \ No newline at end of file -- cgit