Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ********************************************************************** Windows.Forms ***********************************************
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- public int a;
- public int b;
- public int[,] Tablica;
- public void button1_Click(object sender, EventArgs e)
- {
- string s = textBox4.Text;
- a = Convert.ToInt32(s);
- string s1 = textBox4.Text;
- b = Convert.ToInt32(s1);
- if (textBox1.Text == "")
- {
- Tablica = Tablice.Tab.GenTab2D(a, b);
- for (int i = 0; i < a; i++)
- {
- for (int j = 0; j < b; j++)
- {
- textBox1.AppendText(Tablica[i, j].ToString() + "\t");
- }
- textBox1.AppendText("\n");
- }
- }
- }
- public void button2_Click(object sender, EventArgs e)
- {
- if(textBox2.Text=="")
- {
- List<int> Lista = Tablice.Tab.Lista(Tablica, a,b);
- foreach (int liczba in Lista)
- {
- textBox2.AppendText(liczba.ToString() + "\t");
- }
- }
- }
- private void textBox4_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
- *****************************************************Aplikacja Konsolowa*********************************************
- static void Main(string[] args)
- {
- Console.WriteLine("Podaj rozmiar a: ");
- string r1 = Console.ReadLine();
- Console.WriteLine("Podaj rozmiar b: ");
- string r2 = Console.ReadLine();
- int a = int.Parse(r1);
- int b = int.Parse(r2);
- int[,] Tab = Tablice.Tab.GenTab2D(a, b);
- for (int i = 0; i <a; i++) {
- for (int j = 0; j < b; j++)
- {
- Console.Write("{0} \t", Tab[i,j]);
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- int[,] Tab2 = Tablice.Tab.Tabzsilnia(a, b);
- for (int i=0; i<a; i++)
- {
- for(int j=0; j<b; j++)
- {
- Console.Write("{0} \t", Tab2[i, j]);
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- double sredniakwadratowa = Tablice.Tab.SredniaKwadratowa(Tab, a, b);
- Console.Write(sredniakwadratowa);
- Console.WriteLine();
- List<int> Lista = Tablice.Tab.Lista(Tab, a, b);
- foreach(int liczba in Lista)
- {
- Console.Write("{0}\t", liczba);
- }
- Console.ReadKey();
- }
- }
- }
- ****************************************************Biblioteka Klas************************************************************
- public class Tab
- {
- public static int[,] GenTab2D(int R1, int R2)
- {
- Random R = new Random();
- int[,] T = new int[R1, R2];
- for (int i = 0; i < R1; i++)
- for (int j = 0; j < R2; j++)
- {
- T[i, j] = R.Next(100);
- }
- return T;
- }
- public static int[,] PrzekatnaTab2D(int R1, int R2)
- {
- Random R = new Random();
- int[,] T = new int[R1, R2];
- for (int i = 0; i < R1; i++)
- for (int j = 0; j < R2; j++)
- {
- if (i == j)
- {
- T[i, j] = R.Next(100);
- }
- else
- {
- T[i, j] = 1;
- }
- }
- return T;
- }
- public static int[,] Przekatna2Tab2D(int R1, int R2)
- {
- Random R = new Random();
- int[,] T = new int[R1, R2];
- for (int i = 0; i < R1; i++)
- for (int j = 0; j < R2; j++)
- {
- if (i + j == R1 - 1)
- {
- T[i, j] = R.Next(100);
- }
- else
- {
- T[i, j] = 1;
- }
- }
- return T;
- }
- public static int[,] PrzekatneTab2d(int R1, int R2)
- {
- Random R = new Random();
- int[,] T = new int[R1, R2];
- for (int i = 0; i < R1; i++)
- for (int j = 0; j < R2; j++)
- {
- if (i == j)
- {
- T[i, j] = R.Next(100);
- }
- else if (i + j == R1 - 1)
- {
- T[i, j] = R.Next(100);
- }
- else
- {
- T[i, j] = 1;
- }
- }
- return T;
- }
- public static double Srednia(int[,] Tab2d, int R1, int R2)
- {
- int Ilosc = Tab2d.Length;
- double liczba = 0;
- for (int i = 0; i < R1; i++)
- for (int j = 0; j < R2; j++)
- {
- liczba = liczba + Tab2d[i, j];
- }
- double srednia = liczba / Ilosc;
- return srednia;
- }
- public static double SredniaKwadratowa(int[,] Tab2d, int R1, int R2)
- {
- int Ilosc = Tab2d.Length;
- double wynik = 0;
- for (int i = 0; i < R1; i++)
- for (int j = 0; j < R2; j++)
- {
- wynik = wynik + (Tab2d[i, j]*Tab2d[i,j]);
- }
- double srednia = wynik / Ilosc;
- double sredniakwadratowa = Math.Sqrt(srednia);
- return sredniakwadratowa;
- }
- public static double Mediana(int[,] Tab2d, int R1, int R2)
- {
- int Ilosc = Tab2d.Length;
- int [] T = new int[Ilosc];
- int liczba=0;
- while(liczba<Ilosc)
- {
- for (int i=0; i<R1; i++)
- for(int j=0; j<R2; j++)
- {
- T[liczba++] = Tab2d[i, j];
- }
- }
- int polowa;
- double mediana;
- if(Ilosc%2==0)
- {
- polowa = Ilosc / 2;
- mediana = (T[polowa - 1] + T[polowa])/2;
- return mediana;
- }
- else
- {
- polowa = Ilosc / 2;
- mediana = T[polowa];
- return mediana;
- }
- }
- public static int[,] Tabzsilnia (int R1, int R2)
- {
- int[,] T = new int[R1, R2];
- for (int i=0; i<R1;i++)
- for(int j=0; j<R2; j++)
- {
- T[i, j] = Tablice.Tab.Silnia(i, j);
- }
- return T;
- }
- public static int Silnia(int i, int j)
- {
- int suma = i + j;
- int silnia = 1;
- if (suma == 0)
- {
- return 1;
- }
- else
- {
- while(suma>0)
- {
- silnia = silnia * suma;
- suma--;
- }
- return silnia;
- }
- }
- public static int [,] Sortowanie(int[,]Tab2d, int R1, int R2 )
- {
- int ilosc = Tab2d.Length;
- int[] T = new int[ilosc];
- int k = 0;
- while(k<ilosc)
- for(int i=0;i<R1;i++)
- for(int j=0;j<R2;j++)
- {
- T[k++] = Tab2d[i, j];
- }
- int c = 0;
- int n = ilosc;
- do
- {
- for (int i = 0; i < n - 1; i++)
- {
- if (T[i] > T[i + 1])
- {
- int tmp = T[i];
- T[i] = T[i + 1];
- T[i + 1] = tmp;
- }
- }
- n--;
- } while (n > 1);
- int[,] Tab = new int[R1, R2];
- int q = 0;
- while (q < ilosc)
- for (int i = 0; i < R1; i++)
- for (int j = 0; j < R2; j++)
- {
- Tab[i,j]=T[q++];
- }
- return Tab;
- }
- public static List<int> Lista(int[,] Tab2d, int R1, int R2)
- {
- List<int> lista = new List<int>();
- for (int i=0;i<R1;i++)
- for(int j=0;j<R2;j++)
- {
- int suma = 0;
- int counter = 1;
- while (counter < Tab2d[i, j])
- {
- if (Tab2d[i, j] % counter == 0 && counter > 1)
- {
- suma = suma + (Tab2d[i, j] / counter);
- }
- counter++;
- }
- if (suma < Tab2d[i, j])
- {
- lista.Add(Tab2d[i, j]);
- }
- }
- return lista;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement