0% found this document useful (0 votes)
98 views3 pages

Program: Using Using Using Using Namespace Class Static Void Double Int Int For For Double

This document contains C# code that defines methods for inputting elements into a 2D array representing a matrix, transposing that matrix, and performing operations on the elements of the original and transposed matrices. It takes in a matrix from the user, transposes it, and stores the original and transposed matrices in separate arrays. It then analyzes the elements, printing out certain values and properties.

Uploaded by

Zoran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views3 pages

Program: Using Using Using Using Namespace Class Static Void Double Int Int For For Double

This document contains C# code that defines methods for inputting elements into a 2D array representing a matrix, transposing that matrix, and performing operations on the elements of the original and transposed matrices. It takes in a matrix from the user, transposes it, and stores the original and transposed matrices in separate arrays. It then analyzes the elements, printing out certain values and properties.

Uploaded by

Zoran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void upis(double[,] A, int m)
{
int i, j;
for (i = 0; i < m; i++)
{
for (j = 0; j < m; j++)
{
Console.Write("element [{0},{1}]= ", i, j);
A[i, j] = double.Parse(Console.ReadLine());
}
}
}
static double[,] transponovanje(double[,] A)
{
int m = A.GetLength(0);
double[,] transponovana = new double[m, m];
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < m; ++j)
{
transponovana[j, i] = A[i, j];
}
}
return transponovana;

}
static void ispis(double[,] A, int m)
{
Console.WriteLine();
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("Matrica 1 dobijena direktnim unosom");
Console.WriteLine();
int i, j;
for (i = 0; i < m; i++)
{
for (j = 0; j < m; j++)
Console.Write("\t{0}", A[i, j]);
Console.WriteLine();
}
Console.WriteLine();

}
static void ispisT(double[,] B, int m)
{
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("Matrica 2 dobijena transponovanjem originalne matrice");
Console.WriteLine();
int i, j;
for (i = 0; i < m; i++)
{
for (j = 0; j < m; j++)
Console.Write("\t{0}", B[i, j]);
Console.WriteLine();
}
Console.WriteLine();
}
static void elementi(double[,] A, double[,] B, int m)
{
int i, j= 0;
double suma = 0;
Double sredina;
int k = m * m;
for (i = 0; i < m; i++)
{
for (j = 0; j < m; j++)
{
if (i == j)
{
suma = suma + A[i, j];
}
}

}
sredina = suma / m;
if (sredina >= k)
{
Console.WriteLine("Matrica je neispravna");
}

else
{
Console.WriteLine("---------------------------------------------------");
Console.WriteLine("Sledeci niz je niz X");
double[] X = new double[k];
X = B.Cast<double>().ToArray();
foreach (double element in X)
{
Console.Write(element);
Console.Write(", ");
}

Console.WriteLine();
Console.WriteLine("---------------------------------------------------");

double[] Y = new double[k];


for (int p = 0; p < k; p++)
{
if (X[p] < 10)
{
Y[p] = Math.Abs(X[p]) + 1;
}
else
{
Y[p] = Math.Pow(X[p], 2) - 1;
}
}
Console.WriteLine();
Console.WriteLine("---------------------------------------------------");
Console.WriteLine("Sledeci niz je niz Y");

foreach (double element in Y)


{
Console.Write(element);
Console.Write(", ");
}
Console.WriteLine();
}
}
static void Main(string[] args)
{
Console.WriteLine("Unesi broj redova i vrsta matrice");
int m = int.Parse(Console.ReadLine());
if (m > 10)
{
Console.WriteLine("Broj redova i kolona kvadratne matrice ne sme biti
veci od 10");
m = 0;
}

double[,] A = new double[m, m];


double[,] B = new double[m, m];
Console.WriteLine("Unesi elemente matrice");
upis(A, m);
ispis(A, m);
B = transponovanje(A);
elementi(A, B, m);
//ispisT(B, m);

}
}
}

You might also like