Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D Array #282

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
022e3c8
Create name.txt
rachitavya Sep 29, 2022
0087825
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Sep 30, 2022
1f8296f
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 1, 2022
c628940
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 3, 2022
a164fd2
gs1
rachitavya Oct 3, 2022
043e37a
gs2
rachitavya Oct 3, 2022
7385d5d
gs3,4,5
rachitavya Oct 3, 2022
0316c91
renamed
rachitavya Oct 4, 2022
a744203
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 4, 2022
76a6f81
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 4, 2022
92d501b
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 4, 2022
b51be84
Getting Started 6-10
rachitavya Oct 4, 2022
a06380d
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 4, 2022
05612b7
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 4, 2022
d388326
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 5, 2022
29dce52
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 5, 2022
e68c283
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 6, 2022
0b21757
Create pattern1.java
rachitavya Oct 6, 2022
ffd9d27
Create pattern2.java
rachitavya Oct 6, 2022
af30f20
Create pattern3.java
rachitavya Oct 6, 2022
97410f5
Create pattern4.java
rachitavya Oct 6, 2022
3b6d8fb
Create pattern5.java
rachitavya Oct 6, 2022
3e43ccd
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 7, 2022
d69e2c0
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 7, 2022
d63eb21
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 10, 2022
3aa892c
next 5 patterns
rachitavya Oct 10, 2022
9d84459
modified a file
rachitavya Oct 10, 2022
7020fa1
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 10, 2022
aff888a
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 14, 2022
c4cce36
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 18, 2022
9973d91
new folder
rachitavya Oct 18, 2022
baf8304
deletion
rachitavya Oct 18, 2022
6bf0c6c
Create digitfreq.java
rachitavya Oct 20, 2022
9a29729
Delete ML/rachitavya_RachitavyaSharma_2125cs1053_2/FuctionAndArray di…
rachitavya Oct 20, 2022
cbf5f34
Create digitfreq.java
rachitavya Oct 20, 2022
e1a0eb4
Create decToBase.java
rachitavya Oct 20, 2022
98547de
Create baseToDec.java
rachitavya Oct 20, 2022
890e225
Create baseToBase.java
rachitavya Oct 20, 2022
cd4f533
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Oct 28, 2022
f0c08a5
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Nov 2, 2022
83d09f5
Function and arrays
rachitavya Nov 2, 2022
9f38afb
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Nov 3, 2022
4af337a
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Nov 8, 2022
3acc850
New file created
rachitavya Nov 8, 2022
8261ead
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Nov 16, 2022
cd71624
2D Array 1
rachitavya Nov 16, 2022
8fbb7c5
Merge branch 'InnogeeksOrganization:main' into main
rachitavya Nov 23, 2022
2f7ce4e
2D sub
rachitavya Nov 23, 2022
a4e67c5
Merge branch 'main' of https://github.com/rachitavya/coderspree2
rachitavya Nov 23, 2022
f558182
mod in base sub
rachitavya Nov 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ML/rachitavya_RachitavyaSharma_2125cs1053_2/2DArrays/demo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.util.*;

public class demo
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
int n=sc.nextInt();
int a[][]=new int[m][n];
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
a[i][j]=sc.nextInt();
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
sc.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.util.*;

public class matrixmul {

public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n1 = sc.nextInt();
int m1 = sc.nextInt();
int[][] arr1 = new int[n1][m1];

for (int i = 0; i < n1; i++) {
for (int j = 0; j < m1; j++) {
arr1[i][j] = sc.nextInt();
}
}

int n2 = sc.nextInt();
int m2 = sc.nextInt();
int[][] arr2 = new int[n2][m2];

for (int i = 0; i < n2; i++) {
for (int j = 0; j < m2; j++) {
arr2[i][j] = sc.nextInt();
}
}

if (m1 != n2) {
System.out.println("Invalid input");
sc.close();
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();
}
sc.close();

}
}
53 changes: 53 additions & 0 deletions ML/rachitavya_RachitavyaSharma_2125cs1053_2/2DArrays/rotate90.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.io.*;


public class rotate90 {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[][] arr = new int[n][n];

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
arr[i][j] = Integer.parseInt(br.readLine());
}
}

rotateby90(arr);
display(arr);
}

public static void rotateby90(int[][] arr){
// transpose
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < i; j++){
int temp = arr[i][j];
arr[i][j]= arr[j][i];
arr[j][i] = temp;
}
}
// reverse columns, row by row
for(int i = 0; i < arr.length; i++){
int li = 0;
int ri = arr[0].length - 1;
while(li <= ri){
int temp = arr[i][li];
arr[i][li] = arr[i][ri];
arr[i][ri] = temp;

li++;
ri--;
}
}
}
public static void display(int[][] arr){
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr[0].length; j++){
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}

53 changes: 53 additions & 0 deletions ML/rachitavya_RachitavyaSharma_2125cs1053_2/2DArrays/spiral.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.util.*;
public class spiral
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int[][] arr = new int[m][n];

for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
arr[i][j] = sc.nextInt();
}
}

int c=0,r1=0,c1=0,r2=m,c2=n;
while(c<(m*n))
{
for(int i=r1;i<r2;i++)
{
System.out.println(arr[i][c1]);
c++;
}
c1++;
for(int i=c1;i<c2;i++)
{
System.out.println(arr[r2-1][i]);
c++;
}
r2--;
for(int i=(r2-1);i>=r1;i--)
{
System.out.println(arr[i][c2-1]);
c++;
}
c2--;
if(c>=(m*n)) break;
for(int i=(c2-1);i>=c1;i--)
{
System.out.println(arr[r1][i]);
c++;
}
r1++;
}

sc.close();

}

}
38 changes: 38 additions & 0 deletions ML/rachitavya_RachitavyaSharma_2125cs1053_2/2DArrays/wakanda.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.*;

public class wakanda
{

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int[][] arr = new int[m][n];

for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
arr[i][j] = sc.nextInt();
}
}

int c=0;
while(c<n)
{
for(int i=0;i<m;i++)
System.out.println(arr[i][c]);
c++;
if(c<n)
{
for(int i=(m-1);i>=0;i--)
System.out.println(arr[i][c]);
c++;
}
}

sc.close();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.util.*;

public class baseSub
{

public static void main(String[] args)
{
Scanner scn = new Scanner(System.in);
int b = scn.nextInt();
int n1 = scn.nextInt();
int n2 = scn.nextInt();

int d = getDifference(b, n1, n2);
System.out.println(d);
scn.close();
}

public static int getDifference(int b, int n1, int n2)
{
int temp=0,d,i=0,d1,d2,dif=0;
while(n1>0 || n2>0)
{
d1=n1%10;
d2=(n2%10)-temp;
n1/=10;
n2/=10;
if(d2>=d1)
{
d=d2-d1;
temp=0;
}
else
{
d=(d2+b-d1);
temp=1;
}
dif+=d*((int)Math.pow(10,i++));
}
return dif;
}

}