TRENDING NEWS

POPULAR NEWS

User Input Matrix Array. Find The Sum Of Rows Columns And Matrix. - Java

Write a c++ program to find the sum of odd numbers in 2D-array?

include
using namespace std;
void main()
{
int sum=0,arr[10][5]; //example array
for (int i=0;i<10;i++){
for (int j=0;j<10;j++){
if arr[i][j]%2!=0 sum+=arr[i][j];
}
}
cout<}
This above mentioned code should solve your problem

Write a program in c++ to input data into table having 2 rows and 2 columns. calculate the sum and average on the screen?

i got this but there are some errors kindly help me

#include
#include
#include

public static void main(String[] args)
{
int[][] iMat = new int[2][2];

int sum = sumTable(iMat);
int Ave = sumTable(iMat);

}

public static int sumTable(int[][] mat)
{
int total = 0;

for (int i = 0; i < mat.length; i++)
for (int j = 0; j < mat.length; j++)
total += mat[i][j];
Ave== total/2

}
return total;
}

Java program, matrix addition, row sum, column sum?

i need to complete one excerise in java lab
the java program must perform row sum and colum sum
please help me

also please dont give negative comments which is violation and will be reported as abuse

thank you for your answers....!

How do I find the maximum element in each row in a matrix using C?

The very simple code://FINDING MAXIMUM FROM EACH ROW OF MATRIX...#include#define m 20main(){int a[m][m],i,j=0,r,max[10],c;printf("Enter the number of rows");scanf("%d",&r);printf("Enter the number of column");scanf("%d",&c);printf("Enter the elements");for(i=0;imax[i])max[i]=a[i][j];}for(i=0;i

How do I write a C program to find the sum of two matrices?

/* Program to add two matrices entered by the user * /# include
# include
void main ( )
{
int i, j, a[3][3], b[3][3], sum[3][3];
clrscr ( ) ;
printf ("Enter the elements of 1st array .\n") ;
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
scanf ("%d", &a[i][j]) ;
}
}
printf ("Elements of 1st array are: \n") ;
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
printf ("%d\t", a[i][j]) ;
}
printf ("\n") ;
}
printf ("Enter the elements of 2nd array .\n") ;
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
scanf ("%d", &b[i][j]) ;
}
}
printf ("Elements of 2nd array are: \n") ;
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
printf ("%d\t", b[i][j]) ;
}
printf ("\n") ;
}
printf ("The sum of both the matrices are: \n") ;
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
sum[i][j] = a[i][j] + b[i][j];
printf ("%d\t", sum[i][j]) ;
}
printf ("\n") ;
}
getch ( ) ;
}
P.S.- If you want to learn more basic programs like this, then you can check out this app available on Google Play Store. It has basic programs of C, C++ and Java.BCA - Course Programming - Android Apps on Google Play

Java Program Help (2d Arrays)?

Edited:

public static int [][] matrixAdd(int [][]array1, int [][]array2)
{
int [][] c = new int[array1.length][array1[0].length];

for(int row=0; row {
for(int col=0; col {
c[row][col] = array1[row][col] + array2[row][col];
//System.out.printf( "array1[row][col]= %d\n", array1[row][col] );
//System.out.printf( "array2[row][col]= %d\n", array2[row][col] );
//System.out.printf( "arrayC[row][col]= %d\n", c[row][col] );
}
}

return c;
}

Java programing help with 2d array tables?

You forgot to say whats the range of the two dimensional array table, assuming its 5x4
Btw, I wrote this without testing so be reasonable.
If you get an error then its probably because I made a typo somewhere, just look it up and fix it, otherwise this program does what you asked for.
Make sure you put this into a file called :"testProgram.java" without quote.


public class testProgram{

public static int [][] t1 = new int [5][4];

public static int readInt() {
boolean success = false;
int number = 0;
while (!success) {
try {
Scanner scanner = new Scanner(System.in);
number = scanner.nextInt();
success = true;
} catch (InputMismatchException e) {
System.out.print("Wrong format, you have to enter an integer value ");
}
}
return number;
}

public static void fill(int[][]t){

for (int i = 0 ; i < t.length; i++){
for(int k = 0; k < t[i].length){

t1[i][k] = readInt();
}
}
}

private static void output(int[][]t){

for (int a = 0; a < t.length;a++){
for(int b = 0; b System.out.printf("%7d",t[a][b]);
System.out.print(" | ");
}
System.out.println();
}
}


private static void outputAverage(int[][]t){

int [] sum= new int [t.length];

for (int a = 0; a < t.length;a++){
for(int b = 0; b sum[a] =+ t[a][b];
}
}
for (int a = 0; a < t.length;a++){
if(a =0)
System.out.println("The average of the first column is"+sum[a]/4);
if(a =1)
System.out.println("The average of the second column is"+sum[a]/4);
if(a =2)
System.out.println("The average of the third column is"+sum[a]/4);
if(a =3)
System.out.println("The average of the fourth column is"+sum[a]/4);
if(a =4)
System.out.println("The average of the fifth column is"+sum[a]/4);

}
}

public static void main(String[]args){

fill(t1);
output(t1);
outputAverage(t1);
}


}

How do I write a program in Java to multiply two matrices?

Suppose the two matrices are a[][] and b[][].We will multiply a[][] and b[][] and store the result in c[][].Size of c[][]:int a[][]=new int[r1][c1];
int b[][]=new int[r2][c2];
int c[][]=new int[r1][c2];
Condition for multiplication:if(r2!=c1)
//multiplication not possible on a[][] and b[][]
else
//multiplication possible on a[][] and b[][]
Multiplication:for(int x=0;x{
for(int y=0;y {
for(int z=0;z {
c[x][y]+=a[x][z]*b[z][y];
}
}
}

Can someone help me with a Java problem? matrixAdd...?

This is the question:

Write a method named matrixAdd that accepts a pair of two-dimensional arrays of integers as parameters, treats the arrays as 2D matrices and adds them, returning the result. The sum of two matrices A and B is a matrix C where for every row i and column j, Cij = Aij + Bij. You may assume that the arrays passed as parameters have the same dimensions.

This is what I have so far:

public static int[][] matrixAdd(int[][] a, int[][] b){
int[][] result = new int[a.length][b[0].length];
for (int i = 0; i < result.length; i++)
for (int j = 0; j < result[0].length; j++)
result[i][j] = a[i][j] + b[i][j];
return result;
}

It works for the most part, but I need to find a way to return "{}" when the input is matrixAdd({}, {}).
I just get an ArrayIndexOutOfBoundsException.

Please help me. I've tried everything I can think of.

TRENDING NEWS