Semester of MCS-BU: Name: Enayatullah Atal ID: K1S20MCS0003 Date: 4/12/2020 Class: 1 Subj: Advanced Algorithm D&A
Semester of MCS-BU: Name: Enayatullah Atal ID: K1S20MCS0003 Date: 4/12/2020 Class: 1 Subj: Advanced Algorithm D&A
Assignment 02:
Write a pseudo code which find the sum of two 3*3 matrices and then calculate its running
time.
Write a pseudo code which find the Multiplication of two 3*3 matrices and then calculate
its running time.
Write a pseudo code which read a number N and print whether it is prime or not. After that,
calculate the run time complexity.
Write an algorithm using dynamic array to store the result of student and display the result
than delete the array.
1. Write a pseudo code which find the sum of two 3*3 matrices and then calculate its running
time.
We will input the number of row and Column from keyboard and also input the elements of each
row and Column for two matrices.
Sum of two matrices
Step 1: start and also write the time function to calculate the running time
double time_spent =0.0
clock_t begin =clock ()
Step 2: assign four inter variable and three array
Int R, C, B, d, first [3][3], second [3][3], sum [3][3];
Step 3: read the number Row and Column
Read (R, C)
Step 4: read the number of elements for first matrix and used for loop.
for (B = 0; B < R; c++)
for (d = 0; d < C; d++)
read (first[B][d])
Step 5: read the number of second matrix and used for loop.
for (B = 0; B < R; c++)
for (d = 0; d < C; d++)
read (second[B][d])
Step 6: calculate the sum of two matrices
for (B = 0; B < R; c++)
for (d = 0; d < C; d++)
sum[B][d] = first[B][d] + second[B][d]
print (sum[B][d])
Step 7: end the time of running and show the elapsed time in seconds.
clock_t end=clock ()
time_spent +=(double) (end - begin)/ CLOCKS_PER_SEC
print (time spent)
Step 8: [finish]
Exit
2. Write a pseudo code which find the Multiplication of two 3*3 matrices and then calculate
its running time.
Step 9: [finish]
Exit
3. Write a pseudo code which read a number N and print whether it is prime or not. After that,
calculate the run time complexity.
Step 1: start and also write the time function to calculate the running time
double time_spent =0.0
clock_t begin =clock ()
Int n, i, f=0
Step 5: [finish]
Exit
4. Write an algorithm using dynamic array to store the result of student and display the result
than delete the array.
Note: I tried hard to write deletion parts as well but I couldn’t. I hope to guide me in this section.