Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace matrixfeltoltes
- {
- class Program
- {
- /*
- * Főátló alatti elemeket kinullázni
- */
- static double determinans(double[,] tomb)
- {
- double szorzat = 1;
- for (int i = 0; i < tomb.GetLength(1); i++)
- {
- szorzat *= tomb[i, i];
- }
- return szorzat;
- }
- static void kinullazas(double[,] tomb)
- {
- double hanyados, tarolt;
- for(int k = 0; k < tomb.GetLength(0)-1; k++)
- {
- for(int i = k+1; i < tomb.GetLength(0); i++)
- {
- tarolt = tomb[i, k];
- for (int j = k; j < tomb.GetLength(1); j++)
- {
- hanyados = tarolt / tomb[k, k];
- tomb[i, j] = tomb[i, j] + tomb[k, j] * -(hanyados);
- }
- }
- }
- /*for (int i = 1; i < tomb.GetLength(0); i++)
- {
- for (int j = 0; j < tomb.GetLength(1); j++)
- {
- tomb[i, j] = tomb[i, j] + tomb[0, j] * -((double)tomb[i, 0] / (double)tomb[0, 0]);
- }
- }
- for (int i = 2; i < tomb.GetLength(0); i++)
- {
- for (int j = 1; j < tomb.GetLength(1); j++)
- {
- double hanyados = (double)tomb[i, 1] / (double)tomb[1, 1];
- tomb[i, j] = tomb[i, j] + tomb[1, j] * -(hanyados);
- }
- }
- for (int i = 3; i < tomb.GetLength(0); i++)
- {
- for (int j = 2; j < tomb.GetLength(1); j++)
- {
- double hanyados = (double)tomb[i, 2] / (double)tomb[2, 2];
- tomb[i, j] = tomb[i, j] + tomb[2, j] * -(hanyados);
- }
- }*/
- }
- static List<int> lista = new List<int>();
- static void abszelemkereses(double[,] tomb, double max, ref int sorindex, ref int oszlopindex)
- {
- for (int i = 0; i < tomb.GetLength(0); i++)
- {
- for (int j = 0; j < tomb.GetLength(1); j++)
- {
- if (max == Math.Abs(tomb[i, j]))
- {
- sorindex = i;
- oszlopindex = j;
- lista.Add(i + 1);
- lista.Add(j + 1);
- }
- }
- }
- }
- static void elemkereses(double[,] tomb, double max, ref int sorindex, ref int oszlopindex)
- {
- for(int i= 0; i < tomb.GetLength(0); i++)
- {
- for (int j = 0; j < tomb.GetLength(1); j++)
- {
- if(max == tomb[i, j])
- {
- sorindex = i;
- oszlopindex = j;
- lista.Add(i+1);
- lista.Add(j+1);
- }
- }
- }
- }
- static double maxabszkereses(double[,] tomb)
- {
- double max = 0;
- for (int i = 0; i < tomb.GetLength(0); i++)
- {
- for (int j = 0; j < tomb.GetLength(1); j++)
- {
- if (max < Math.Abs(tomb[i, j]))
- {
- max = Math.Abs(tomb[i, j]);
- }
- }
- }
- return max;
- }
- static double maxkereses(double[,] tomb)
- {
- double max = 0;
- for(int i = 0; i < tomb.GetLength(0); i++)
- {
- for (int j = 0; j < tomb.GetLength(1); j++)
- {
- if(max < tomb[i, j])
- {
- max = tomb[i, j];
- }
- }
- }
- return max;
- }
- static void feltolt(double[,] tomb, Random vel)
- {
- for(int i = 0; i < tomb.GetLength(0); i++)
- {
- for (int j = 0; j < tomb.GetLength(1); j++)
- {
- tomb[i, j] = vel.Next(-100, 100);
- }
- }
- }
- static void kiir(double[,] tomb)
- {
- for(int i = 0; i < tomb.GetLength(0); i++)
- {
- for(int j = 0; j < tomb.GetLength(1); j++)
- {
- Console.Write("{0,3:00.00} ", tomb[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- Console.Write("Paraszt írd be a dimnezió számát: ");
- int n = Convert.ToInt16(Console.ReadLine());
- int sorindex=0, oszlopindex=0;
- double[,] tomb = new double[n, n];
- double[,] tomb2 = new double[n, n];
- Random vel = new Random();
- feltolt(tomb, vel);
- kiir(tomb);
- Console.WriteLine("Ez itt a legnagyobb elem: {0}", maxkereses(tomb));
- Console.WriteLine("Ez itt a legnagyobb abszolútértékű elem: {0}", maxabszkereses(tomb));
- elemkereses(tomb, maxkereses(tomb), ref sorindex, ref oszlopindex);
- Console.WriteLine("A maximális elem sorindexe: {0}, oszlopindexe: {1}", sorindex+1, oszlopindex+1);
- Console.WriteLine("A maximális elemek száma: {0}", lista.Count/2);
- for (int i = 0; i < lista.Count; i++)
- {
- Console.Write("{0} ", lista[i]);
- if (i % 2 == 0)
- {
- Console.WriteLine();
- }
- }
- Console.WriteLine();
- lista.Clear();
- abszelemkereses(tomb, maxabszkereses(tomb), ref sorindex, ref oszlopindex);
- Console.WriteLine("A maximális abszolútértékű elem sorindexe: {0}, oszlopindexe: {1}", sorindex + 1, oszlopindex + 1);
- Console.WriteLine("A maximális abszolútértékű elemek száma: {0}", lista.Count / 2);
- for (int i = 0; i < lista.Count; i++)
- {
- Console.Write("{0} ", lista[i]);
- if (i % 2 == 0)
- {
- Console.WriteLine();
- }
- }
- Console.WriteLine();
- kinullazas(tomb);
- kiir(tomb);
- Console.WriteLine("A mátrix determinánsa: {0}", determinans(tomb));
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement