Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.79 KB | None | 0 0
  1. ********************************************************************** Windows.Forms ***********************************************
  2. public partial class Form1 : Form
  3. {
  4. public Form1()
  5. {
  6. InitializeComponent();
  7. }
  8.  
  9. private void Form1_Load(object sender, EventArgs e)
  10. {
  11.  
  12. }
  13.  
  14. private void textBox1_TextChanged(object sender, EventArgs e)
  15. {
  16.  
  17. }
  18. public int a;
  19. public int b;
  20. public int[,] Tablica;
  21.  
  22. public void button1_Click(object sender, EventArgs e)
  23. {
  24. string s = textBox4.Text;
  25. a = Convert.ToInt32(s);
  26. string s1 = textBox4.Text;
  27. b = Convert.ToInt32(s1);
  28.  
  29. if (textBox1.Text == "")
  30. {
  31. Tablica = Tablice.Tab.GenTab2D(a, b);
  32. for (int i = 0; i < a; i++)
  33. {
  34. for (int j = 0; j < b; j++)
  35. {
  36. textBox1.AppendText(Tablica[i, j].ToString() + "\t");
  37. }
  38. textBox1.AppendText("\n");
  39. }
  40. }
  41.  
  42. }
  43.  
  44.  
  45. public void button2_Click(object sender, EventArgs e)
  46. {
  47. if(textBox2.Text=="")
  48. {
  49. List<int> Lista = Tablice.Tab.Lista(Tablica, a,b);
  50. foreach (int liczba in Lista)
  51. {
  52. textBox2.AppendText(liczba.ToString() + "\t");
  53. }
  54. }
  55. }
  56.  
  57. private void textBox4_TextChanged(object sender, EventArgs e)
  58. {
  59.  
  60. }
  61. }
  62. }
  63.  
  64. *****************************************************Aplikacja Konsolowa*********************************************
  65. static void Main(string[] args)
  66. {
  67. Console.WriteLine("Podaj rozmiar a: ");
  68. string r1 = Console.ReadLine();
  69. Console.WriteLine("Podaj rozmiar b: ");
  70. string r2 = Console.ReadLine();
  71.  
  72. int a = int.Parse(r1);
  73. int b = int.Parse(r2);
  74. int[,] Tab = Tablice.Tab.GenTab2D(a, b);
  75. for (int i = 0; i <a; i++) {
  76. for (int j = 0; j < b; j++)
  77. {
  78. Console.Write("{0} \t", Tab[i,j]);
  79. }
  80. Console.WriteLine();
  81. }
  82. Console.WriteLine();
  83.  
  84. int[,] Tab2 = Tablice.Tab.Tabzsilnia(a, b);
  85. for (int i=0; i<a; i++)
  86. {
  87. for(int j=0; j<b; j++)
  88. {
  89. Console.Write("{0} \t", Tab2[i, j]);
  90. }
  91. Console.WriteLine();
  92. }
  93. Console.WriteLine();
  94.  
  95. double sredniakwadratowa = Tablice.Tab.SredniaKwadratowa(Tab, a, b);
  96. Console.Write(sredniakwadratowa);
  97. Console.WriteLine();
  98.  
  99. List<int> Lista = Tablice.Tab.Lista(Tab, a, b);
  100. foreach(int liczba in Lista)
  101. {
  102. Console.Write("{0}\t", liczba);
  103. }
  104.  
  105. Console.ReadKey();
  106. }
  107. }
  108. }
  109.  
  110. ****************************************************Biblioteka Klas************************************************************
  111.  
  112. public class Tab
  113. {
  114. public static int[,] GenTab2D(int R1, int R2)
  115. {
  116. Random R = new Random();
  117. int[,] T = new int[R1, R2];
  118. for (int i = 0; i < R1; i++)
  119. for (int j = 0; j < R2; j++)
  120. {
  121. T[i, j] = R.Next(100);
  122. }
  123. return T;
  124. }
  125.  
  126. public static int[,] PrzekatnaTab2D(int R1, int R2)
  127. {
  128. Random R = new Random();
  129. int[,] T = new int[R1, R2];
  130. for (int i = 0; i < R1; i++)
  131. for (int j = 0; j < R2; j++)
  132. {
  133. if (i == j)
  134. {
  135. T[i, j] = R.Next(100);
  136. }
  137. else
  138. {
  139. T[i, j] = 1;
  140. }
  141. }
  142. return T;
  143. }
  144.  
  145. public static int[,] Przekatna2Tab2D(int R1, int R2)
  146. {
  147. Random R = new Random();
  148. int[,] T = new int[R1, R2];
  149. for (int i = 0; i < R1; i++)
  150. for (int j = 0; j < R2; j++)
  151. {
  152. if (i + j == R1 - 1)
  153. {
  154. T[i, j] = R.Next(100);
  155. }
  156. else
  157. {
  158. T[i, j] = 1;
  159. }
  160. }
  161. return T;
  162. }
  163.  
  164. public static int[,] PrzekatneTab2d(int R1, int R2)
  165. {
  166. Random R = new Random();
  167. int[,] T = new int[R1, R2];
  168. for (int i = 0; i < R1; i++)
  169. for (int j = 0; j < R2; j++)
  170. {
  171. if (i == j)
  172. {
  173. T[i, j] = R.Next(100);
  174. }
  175. else if (i + j == R1 - 1)
  176. {
  177. T[i, j] = R.Next(100);
  178. }
  179. else
  180. {
  181. T[i, j] = 1;
  182. }
  183. }
  184. return T;
  185. }
  186.  
  187. public static double Srednia(int[,] Tab2d, int R1, int R2)
  188. {
  189. int Ilosc = Tab2d.Length;
  190. double liczba = 0;
  191. for (int i = 0; i < R1; i++)
  192. for (int j = 0; j < R2; j++)
  193. {
  194. liczba = liczba + Tab2d[i, j];
  195. }
  196. double srednia = liczba / Ilosc;
  197. return srednia;
  198. }
  199.  
  200. public static double SredniaKwadratowa(int[,] Tab2d, int R1, int R2)
  201. {
  202. int Ilosc = Tab2d.Length;
  203. double wynik = 0;
  204. for (int i = 0; i < R1; i++)
  205. for (int j = 0; j < R2; j++)
  206. {
  207. wynik = wynik + (Tab2d[i, j]*Tab2d[i,j]);
  208. }
  209. double srednia = wynik / Ilosc;
  210. double sredniakwadratowa = Math.Sqrt(srednia);
  211. return sredniakwadratowa;
  212. }
  213.  
  214.  
  215. public static double Mediana(int[,] Tab2d, int R1, int R2)
  216. {
  217. int Ilosc = Tab2d.Length;
  218. int [] T = new int[Ilosc];
  219. int liczba=0;
  220.  
  221. while(liczba<Ilosc)
  222. {
  223. for (int i=0; i<R1; i++)
  224. for(int j=0; j<R2; j++)
  225. {
  226. T[liczba++] = Tab2d[i, j];
  227. }
  228. }
  229. int polowa;
  230. double mediana;
  231. if(Ilosc%2==0)
  232. {
  233. polowa = Ilosc / 2;
  234. mediana = (T[polowa - 1] + T[polowa])/2;
  235. return mediana;
  236. }
  237. else
  238. {
  239. polowa = Ilosc / 2;
  240. mediana = T[polowa];
  241. return mediana;
  242. }
  243. }
  244.  
  245. public static int[,] Tabzsilnia (int R1, int R2)
  246. {
  247. int[,] T = new int[R1, R2];
  248. for (int i=0; i<R1;i++)
  249. for(int j=0; j<R2; j++)
  250. {
  251. T[i, j] = Tablice.Tab.Silnia(i, j);
  252. }
  253. return T;
  254. }
  255.  
  256. public static int Silnia(int i, int j)
  257. {
  258. int suma = i + j;
  259. int silnia = 1;
  260. if (suma == 0)
  261. {
  262. return 1;
  263. }
  264. else
  265. {
  266. while(suma>0)
  267. {
  268. silnia = silnia * suma;
  269. suma--;
  270. }
  271. return silnia;
  272. }
  273. }
  274.  
  275. public static int [,] Sortowanie(int[,]Tab2d, int R1, int R2 )
  276. {
  277. int ilosc = Tab2d.Length;
  278. int[] T = new int[ilosc];
  279. int k = 0;
  280. while(k<ilosc)
  281. for(int i=0;i<R1;i++)
  282. for(int j=0;j<R2;j++)
  283. {
  284. T[k++] = Tab2d[i, j];
  285. }
  286. int c = 0;
  287. int n = ilosc;
  288. do
  289. {
  290. for (int i = 0; i < n - 1; i++)
  291. {
  292. if (T[i] > T[i + 1])
  293. {
  294. int tmp = T[i];
  295. T[i] = T[i + 1];
  296. T[i + 1] = tmp;
  297. }
  298. }
  299. n--;
  300. } while (n > 1);
  301. int[,] Tab = new int[R1, R2];
  302. int q = 0;
  303. while (q < ilosc)
  304. for (int i = 0; i < R1; i++)
  305. for (int j = 0; j < R2; j++)
  306. {
  307. Tab[i,j]=T[q++];
  308. }
  309. return Tab;
  310. }
  311.  
  312. public static List<int> Lista(int[,] Tab2d, int R1, int R2)
  313. {
  314. List<int> lista = new List<int>();
  315. for (int i=0;i<R1;i++)
  316. for(int j=0;j<R2;j++)
  317. {
  318. int suma = 0;
  319. int counter = 1;
  320. while (counter < Tab2d[i, j])
  321. {
  322. if (Tab2d[i, j] % counter == 0 && counter > 1)
  323. {
  324. suma = suma + (Tab2d[i, j] / counter);
  325. }
  326. counter++;
  327. }
  328. if (suma < Tab2d[i, j])
  329. {
  330. lista.Add(Tab2d[i, j]);
  331. }
  332. }
  333. return lista;
  334. }
  335. }
  336. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement