diff --git a/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/2d array demo.cpp b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/2d array demo.cpp new file mode 100644 index 00000000..8acb9a82 --- /dev/null +++ b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/2d array demo.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +int main() { + int n; + int m; + cin >> n; + cin >> m; + + vector>marr; + for (int i = 0; i < n; i++) { + vectorsarr; + for (int j = 0; j < m; j++) { + int ele; + cin >> ele; + sarr.push_back(ele); + } + marr.push_back(sarr); + } + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cout << marr[i][j] << " "; + } + cout << endl; +  } +} diff --git a/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/The state of wakanda 1.cpp b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/The state of wakanda 1.cpp new file mode 100644 index 00000000..4c19077a --- /dev/null +++ b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/The state of wakanda 1.cpp @@ -0,0 +1,44 @@ +#include +#include + +using namespace std; + +void columnTraversal(vector> mat) { + int row = mat.size(); + int col = mat[0].size(); + + for (int c = 0; c < col; c++) { + if (c % 2 == 0) { + for (int r = 0; r < row; r++) { + cout << mat[r][c]; + cout << endl; + } + } + else { + for (int r = row - 1; r >= 0; r--) { + cout << mat[r][c]; + cout << endl; + } + } + } +} + +int main() { + int n; + int m; + cin >> n; + cin >> m; + + vector> mat; + for (int i = 0; i < n; i++) { + vector arr; + for (int j = 0; j < m; j++) { + int ele; + cin >> ele; + arr.push_back(ele); + } + mat.push_back(arr); + } + + columnTraversal(mat); +} diff --git a/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/matrixmultiplication.java b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/matrixmultiplication.java new file mode 100644 index 00000000..c945dd05 --- /dev/null +++ b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/matrixmultiplication.java @@ -0,0 +1,54 @@ +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n1 = Integer.parseInt(br.readLine()); + int m1 = Integer.parseInt(br.readLine()); + int[][] arr1 = new int[n1][m1]; + + for (int i = 0; i < n1; i++) { + for (int j = 0; j < m1; j++) { + arr1[i][j] = Integer.parseInt(br.readLine()); + } + } + + int n2 = Integer.parseInt(br.readLine()); + int m2 = Integer.parseInt(br.readLine()); + int[][] arr2 = new int[n2][m2]; + + for (int i = 0; i < n2; i++) { + for (int j = 0; j < m2; j++) { + arr2[i][j] = Integer.parseInt(br.readLine()); + } + } + + if (m1 != n2) { + System.out.println("Invalid input"); + return; + } + + int[][] prd = new int[n1][m2]; + for (int i = 0; i < n1; i++) { + for (int j = 0; j < m2; j++) { + int sum = 0; + + for (int k = 0; k < m1; k++) { + sum += arr1[i][k] * arr2[k][j]; + } + + prd[i][j] = sum; + } + } + + for (int i = 0; i < n1; i++) { + for (int j = 0; j < m2; j++) { + System.out.print(prd[i][j] + " "); + } + System.out.println(); +      } + +   } +} \ No newline at end of file diff --git a/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/spiral display.cpp b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/spiral display.cpp new file mode 100644 index 00000000..cc56d903 --- /dev/null +++ b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/2D arrays/spiral display.cpp @@ -0,0 +1,61 @@ +#include +using namespace std; + +const int mr = 100, mc = 100; +void inputBound(int (&mat)[mr][mc], int n, int m) +{ + + for (int i = 0; i < n; i++) + { + for (int j = 0; j < m; j++) + { + cin >> mat[i][j]; + } + } +} + +int main(int argc, char** argv) +{ + + + int mat[mr][mc] = {0}; + int n, m; + cin >> n >> m; + + inputBound(mat, n, m); + int toe = n * m; + int count = 0; + int minr = 0, minc = 0, maxr = n - 1, maxc = m - 1; + + while (count < toe) + { + + //left wall + for (int i = minr, j = minc ; i <= maxr && count < toe ; i++) { + cout << mat[i][minc] << endl; + count++; + } + minc++; + //bottom wall + for (int i = maxr, j = minc ; j <= maxc && count < toe ; j++) { + cout << mat[maxr][j] << endl; + count++; + } + maxr--; + //right wall + for (int i = maxr, j = maxc ; i >= minr && count < toe ; i--) { + cout << mat[i][maxc] << endl; + count++; + } + maxc--; + //top wall + for (int i = minr, j = maxc ; j >= minc && count < toe ; j--) { + cout << mat[minr][j] << endl; + count++; + } + minr++; + } + // write your code here + +  return 0; +} diff --git a/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/patterns/pattern4.cpp b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/patterns/pattern4.cpp new file mode 100644 index 00000000..98c7b522 --- /dev/null +++ b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/patterns/pattern4.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; + +// Pattern 4 +void pattern4(int n) +{ + + int k = 2 * n - 2; + + + for (int i = n; i > 0; i--) { + + for (int j = 0; j < n - i; j++) + cout << " "; + k = k - 2; + + for (int j = 0; j < i; j++) { + + cout << "* "; + } + + + cout << endl; + } +} + +int main() +{ + int n = 5; + + + pattern4(n); +    return 0; +} diff --git a/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/patterns/pattern5.cpp b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/patterns/pattern5.cpp new file mode 100644 index 00000000..41833960 --- /dev/null +++ b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/patterns/pattern5.cpp @@ -0,0 +1,32 @@ +using namespace std; + +int main() +{ + int n, c, k, space = 1; + + cout << “\nEnter the number of rows : “; + cin >> n; + + space = n – 1; + + for (k = 1; k <= n; k++) + { + for (c = 1; c <= space; c++) + cout << ” “; + space--; + for (c = 1; c <= 2*k-1; c++) + cout << “*”; + cout << endl; +} + space = 1; + for (k = 1; k <= n – 1; k++) + { + for (c = 1; c <= space; c++) + cout << ” “; + space++; + for (c = 1 ; c <= 2*(n-k)-1; c++) + cout << “*”; + cout << endl; + } + return 0; +} diff --git a/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/patterns/pattern6.cpp b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/patterns/pattern6.cpp new file mode 100644 index 00000000..5abcdc2c --- /dev/null +++ b/AR-VR/Shubhipandey21_ShubhiPandey_2125csit1169_2/patterns/pattern6.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; +int main() +{ + int i, j, n=3; + for(i = 0; i < n; i++) + { + for(j = 0; j < (2 * n); j++) + { + if(i + j <= n - 1) + cout << "*"; + else + cout << " "; + if((i + n) <= j) + cout << "*"; + else + cout << " "; + } + cout << "\n"; + } + + for(i = 1; i < n; i++) + { + for(j = 0; j < (2 * n); j++) + { + if(i >= j) + cout << "*"; + else + cout << " "; + if(i >= (2 * n - 1) - j) + cout << "*"; + else + cout << " "; + } + cout << "\n"; + } +    return 0; +}