diff --git a/Q2-linear search.py b/Q2-linear search.py new file mode 100644 index 0000000..abb5a7b --- /dev/null +++ b/Q2-linear search.py @@ -0,0 +1,20 @@ +def linearsrch(mat,a,x): + i=0 + j=a-1 + while(i=0): + if mat[i][j]==x: + print("found at(",i,",",j,")") + return 1 + if(mat[i][j]>x): + j-=1 + else: + i+=1 + print("not found") + return 0 + +y=[ [10,20,30,40], + [15,25,35,45], + [27,29,37,48], + [32,33,39,50] ] +b=int(input("enter the element to be searched: ")) +linearsrch(y,4,b) diff --git a/q1-prime.py b/q1-prime.py new file mode 100644 index 0000000..8278f2f --- /dev/null +++ b/q1-prime.py @@ -0,0 +1,30 @@ +def prime(n): + if n>1: + for i in range(2,n//2): + if(n%i)==0: + return False + else: + return True + else: + return False + +l=[[1,2,3,4], + [5,6,7,8], + [9,10,11,12]] +n=3 +m=4 +count=0 +for i in range(n): + for j in range(m): + sum=0 + if 0<=i-1: + sum+=l[i-1][j] + if 0<=j-1: + sum+=+l[i][j-1] + if i+1<= n-1: + sum+= l[i+1][j] + if j+1<=m-1: + sum+= l[i][j+1] + if prime(sum): + count+=1 +print("Number of adjacent prime number sum: ",count) diff --git a/q3-odd number.py b/q3-odd number.py new file mode 100644 index 0000000..225e58c --- /dev/null +++ b/q3-odd number.py @@ -0,0 +1,12 @@ +a=[[0,0,1,0], + [1,0,0,1], + [1,1,1,0]] +count=0 +for j in range(3): + sum=0 + for i in range(2): + sum+=a[i][j] + if sum%2==1: + count+=1 + +print("output",count)