0% found this document useful (0 votes)
3 views

Algorithms Object Array

The document outlines ten different programs focusing on various algorithms and operations on arrays and matrices. Each program includes a series of steps for tasks such as finding common elements, transposing matrices, merging arrays, checking for symmetry, and identifying saddle points. The programs are structured in a clear, sequential manner to facilitate understanding and implementation.

Uploaded by

rehantarafdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Algorithms Object Array

The document outlines ten different programs focusing on various algorithms and operations on arrays and matrices. Each program includes a series of steps for tasks such as finding common elements, transposing matrices, merging arrays, checking for symmetry, and identifying saddle points. The programs are structured in a clear, sequential manner to facilitate understanding and implementation.

Uploaded by

rehantarafdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Algorithms

Object Based Programs

Program 1

Step 1: Start
Step 2: Declare an array arr of size 100, arr2 of size len, set J=0
Step 3: Read integers into array of len numbers
Step 4: run loop from I=0 to len
Step 5: compare the elements of two arrays at Ith position
Step 6: if they are equal, store the element in arr2[Jth] location
Step 7: increment I by 1
Step 8: end loop
Step 9: Print the array with common elements and loop
Step 10: Stop

Program 2

Step 1: Declare a double dimension array of size M x N


Step 2: Read elements into the array
Step 3: run outer loop from I=0 to M
Step 4: run inner loop from J=0 to N
Step 5: Temp=array [I][J]
Step 6: array[I][J] = array [J]{I]
Step 7: array [J][I] = Temp
Step 8: increment J by 1
Step 9: increment I by 1
Step 10: End inner loop
Step 11: End outer loop
Step 12: Print transposed array
Step 13: Stop

Program 3

Step 1: Declare two integer arrays of size N


Step 2: Read elements into the arrays
Step 3: Enter the number whose frequency to be checked in K
Step 4: Run loop from I=0 to N
Step 5: Check if array1[I]=K then increment CTR by 1
Step 6: End loop
Step 7: Declare a third array of size array1.N + array2.N, set X=0
Step 8: Run loop from I=0 to array1.N
Step 9: Shift the elements of array1 to array 3 by array3[X++]=array1[I]
Step 10: Increment I by 1
Step 11: End loop
Step 12: Run a loop from I=0 to array2.N
Step 13: Shift the elements of array2 to array 3 by array3[X++]=array2[I]
Step 14: Increment I by 1
Step 15: End loop
Step 16: Print the merged array
Step 17: Stop

Program 4

Start 1: Start
Step 2: Read hours and mins of Time1
Step 3: Read hours and mins of Time2
Step 4: Create a temporary object Time3
Step 5: Perform Time3->hours= Time1->hours+Time->hours
Step 6: Perform Time3->min= Time1>min+Time2>min
Step 7: If Time3.mins >=60 then
Step 8: Time3->hours+=Time3->min/60
Step 9: Time3->mins=Time3->min%60
Step 10: Display Time3
Step 11: Stop

Program 5

Step 1: Start
Step 2: Read the value of row and column and declare matrix A[r][c], B[r][c], C[r][c]
Step 3: Read the values in A[][] and B[][]
Step 4: Declare variable i=0, j=0
Step 5: Repeat until i < r
Step 6: Repeat until j < c
Step7: Perform C[i][j]=A[i][j] - B[i][j]
Step 8: Set j=j+1
Step 9: End inner loop
Step 10: Set i=i+1
Step 11: End outer loop
Step 12: display matrix C[][]
Step 13: Stop

ARRAY BASED PROGRAMS

Program 6

Step 1: Start
Step 2: Declare a matrix A[m][m]
Step 3: Read values in matrix A
Step 4: Run loop from I=0 to m
Step 5: Run loop from J=0 to m
Step 6: check if A[I][J] ≠ A[J][I] then
Step 7: Print array is not symmetric
Step 8: Terminate loop
Step 9: End loop
Step 10: End loop
Step 11: Print Array is symmetric
Step 12: Run loop from I=0 to m
Step 13: Set SUM1+= A[I][I]
Step 14: Set SUM2+=A[J][I]
Step 15: End loop
Step 16: Print SUM1 and SUM2
Step 17: Stop

Program 7

Step 1: Start
Step 2: Read rows and column in m and n
Step 3: Read values in array
Step 4: Run loop from I=0 to m
Step 5: Run loop from J=0 to m
Step 6: check if (I=0) or (I=(m-1)) or (J=0) or (J=(n-1))
Step 7: Print A[I][J]
Step 8: End loop
Step 9: End loop

Program 8 Magic Square

Step 1: Start
Step 2: Read a matrix A[][] of mxm size
Step 3: Set RSUM=0, CSUM=0, D=0
Step 4: Run loop from I =0 to M
Step 5: D=D+A[I][I]
Step 6; End loop
Step 7: Run loop from I =0 to M
Step 8: Set RSUM=0, CSUM=0
Step 9: Run loop from J=0 to M
Step 10: RSUM=RSUM+A[I][J]
Step 11: CSUM=CSUM+A[J][I]
Step 12: end loop
Step 13: If CSUM ≠D or RSUM ≠ D then Set FLAG= FALSE
Step 14: Print Not Magic Square
Step 15: terminate loop
Step 16: End loop
Step 17: If FLAG=TRUE then
Step 18: Print Magic Square
Step 19: Stop

Program 9 Saddle Point

Step 1: Start
Step 2: Read elements in matrix MAT[][] of mxm size
Step 3: Run loop from I=0 to M
Step 4: Set MINROW=MAT[I][0] and COLIND = 0
Step 5: Run loop J=1 to M
Step 6: If MINROW> MAT[I][J] then
Step 7: MINROW=MAT[I][J] and COLIND=J
Step 8: End loop
Step 9: Run loop K=0 to M
Step 10: If MINROW< MAT[K][COLIND] then end loop
Step 11: If K=M then
Step 12: Print Saddle point is MINROW
Step 13: end loop
Step 13: Stop

Program 10 Upper Triangular Matrix

STEP 1: START

STEP 2: DEFINE rows, cols

STEP 3: INITIALIZE matrix a[][] ={{1,2,3},{8, 6, 4}, {4, 5, 6}}

STEP 4: rows = a.length

STEP 5: cols = a[0].length

STEP 6: if(rows!=cols)
then PRINT "Matrix should be a square matrix" else Go to step 7

STEP 7: REPEAT STEP 8 to STEP 10 UNTIL i<rows


STEP 8: REPEAT STEP 9 UNTIL j<cols

STEP 9: If(i>j) then PRINT 0 else PRINT a[i][j]

STEP 10: PRINT new line

STEP 11: END

You might also like