static double[][] transpose(double[][] array)
{
double[][] tmatrix = new double[array.length][array.length];
for(int i = 0; i < array.length; ++i)
{
for(int j = 0; j < array.length; ++j)
{
tmatrix[j][i] = array[i][j];
}
}
return tmatrix;
}
static void print(double[][] array)
{
double sumLine = 0;
double sumTomb = 0;
double[][] tmatrix = transpose(array);
for (int i = 0; i < array.length; ++i)
{
for(int j = 0; j < array.length; ++j)
{
sumTomb += tmatrix[i][j];
sumLine += array[i][j];
System.out.print(array[i][j] + " ");
}
System.out.println("MiddleNumLine " + sumLine / array.length + " MiddleNumTomb " + sumTomb / array.length);
sumLine = 0;
sumTomb = 0;
}
}
public static void main(String[] args) {
Scanner num = new Scanner(System.in);
System.out.println ("Введите размер матрицы ");
int size = num.nextInt();
double[][] array = createRandomArray(size);
print(array);
}
int[][] array = new int[size][size];
int **arr = new int*[n];
for (int i = 0; i < n; ++i)
{
arr[i] = new int[n];
}
public class MT
{
static double[][] createRandomArray(int size) {
double[][] array = new double[size][size];
for(int i = 0; i < array.length; i++) {
for(int j = 0; j < array[i].length; j++) {
array[i][j] = (Math.random() * 10);
}
}
return array;
}
static void middleNumByLine(double[][] array)
{
double sum = 0;
for(int i = 0; i < array.length; ++i)
{
for(int j = 0; j < array.length; ++j)
{
sum += array[i][j];
}
System.out.println(sum/array.length);
sum = 0;
}
}
static void middleNumByTomb(double[][] array)
{
double sum = 0;
for(int i = 0; i < array.length; ++i)
{
for(int j = 0; j < array.length; ++j)
{
sum += array[j][i];
}
System.out.println(sum/array.length);
sum = 0;
}
}
static void print(double[][] array)
{
for (int i = 0; i < array.length; ++i)
{
for(int j = 0; j < array.length; ++j)
{
System.out.print(array[i][j] + " ");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner num = new Scanner(System.in);
System.out.println ("Введите размер матрицы ");
int size = num.nextInt();
double[][] array = createRandomArray(size);
print(array);
System.out.println("________________");
middleNumByLine(array);
System.out.println("________________");
middleNumByTomb(array);
}
}
//В строке
static void middleNumByLine(double[][] array)
{
double sum = 0;
for(int i = 0; i < array.length; ++i)
{
for(int j = 0; j < array.length; ++j)
{
sum += array[i][j];
}
System.out.println(sum / array.length);
sum = 0;
}
}
//В столбце
static void middleNumByTomb(double[][] array)
{
double sum = 0;
for(int i = 0; i < array.length; ++i)
{
for(int j = 0; j < array.length; ++j)
{
sum += array[j][i];
}
System.out.println(sum / array.length);
sum = 0;
}
}
for(int i=0; i<da.length; i++) {
for(int j=0; j<da[i].length; j++) {
System.out.print(da[i][j] + "\t");
System.out.println("["+mean(da[i])+"]");
System.out.println("["+mean(da[j])+"]");
}
System.out.println();
}