Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. int[] tab1 = new int[6];
  6. int[,] tab2 = new int[6, 6];
  7. //int[][] tab3 = new int[][];
  8. int suma1 = 0, suma2 = 0, sumaKolejnych1 = 0, sumaKolejnych2 = 0, liczbaElementow1 = 0, liczbaElementow2 = 0;
  9. double srednia1, srednia2, sredniaKolejnych1, sredniaKolejnych2;
  10.  
  11. // 1 tablica :
  12. //liczba:
  13. Console.Write("Podaj liczbę do 1 tablicy: ");
  14. int podanaLiczba = Convert.ToInt32(Console.ReadLine());
  15. for (int i=0; i < 6; i++)
  16. {
  17. tab1[i] = podanaLiczba;
  18. Console.Write(tab1[i].ToString() + " ");
  19. }
  20.  
  21. for (int i = 0; i < 5; i++)
  22. {
  23. suma1 += tab1[i];
  24. liczbaElementow1 += 1;
  25. }
  26.  
  27. srednia1 = suma1 / liczbaElementow1;
  28. Console.WriteLine();
  29. Console.WriteLine("Suma 1: " + suma1.ToString() + "\nSrednia 1: " + srednia1.ToString());
  30.  
  31. //kolejne liczby:
  32.  
  33. Console.Write("Podaj liczbę do tablicy 1 ( kolejne liczby) : ");
  34. int kolejneLiczby1 = Convert.ToInt32(Console.ReadLine());
  35. for (int i = 0; i < 5; i++, kolejneLiczby1++)
  36. {
  37. tab1[i] = kolejneLiczby1;
  38. Console.Write(tab1[i].ToString() + " ");
  39. }
  40. liczbaElementow1 = 0;
  41. for (int i = 0; i < 5; i++)
  42. {
  43. sumaKolejnych1 += tab1[i];
  44. liczbaElementow1 += 1;
  45. }
  46. sredniaKolejnych1 = sumaKolejnych1 / liczbaElementow1;
  47. Console.WriteLine();
  48. Console.WriteLine("Suma 1: " + sumaKolejnych1.ToString() + "\nSrednia 1: " + sredniaKolejnych1.ToString());
  49.  
  50. // 2 tablica :
  51.  
  52. //takie same liczby:
  53.  
  54. Console.Write("Podaj liczbę do 2 tablicy: ");
  55. int podanaLiczba2 = Convert.ToInt32(Console.ReadLine());
  56. for (int i = 0; i < 6; i++)
  57. {
  58. for (int j = 0; j < 6; j++)
  59. {
  60. tab2[i, j] = podanaLiczba2;
  61. Console.Write(tab2[i, j].ToString() + " ");
  62. }
  63. Console.WriteLine();
  64.  
  65. }
  66. for (int i = 0; i < 5; i++)
  67. {
  68. for (int j = 0; j < 5; j++)
  69. {
  70. suma2 += tab2[i, j];
  71. liczbaElementow2 += 1;
  72. }
  73. }
  74. srednia2 = suma2 / liczbaElementow2;
  75. Console.WriteLine();
  76. Console.WriteLine("Suma 2: " + suma2.ToString() + "\nSrednia 2: " + srednia2.ToString());
  77.  
  78. // kolejne liczby:
  79. Console.Write("Podaj liczbę do tablicy 2 ( kolejne liczby) : ");
  80. int kolejneLiczby2 = Convert.ToInt32(Console.ReadLine());
  81. for (int i = 0; i < 5; i++)
  82. {
  83. for (int j = 0; j < 5; j++, kolejneLiczby2++)
  84. {
  85. tab2[i, j] = kolejneLiczby2;
  86. Console.Write(tab2[i, j].ToString() + " ");
  87. }
  88. Console.WriteLine();
  89. }
  90. liczbaElementow2 = 0;
  91. for (int i = 0; i < 5; i++)
  92. {
  93. for (int j = 0; j < 5; j++)
  94. {
  95. sumaKolejnych2 += tab2[i, j];
  96. liczbaElementow2 += 1;
  97. }
  98. }
  99. sredniaKolejnych2 = sumaKolejnych2 / liczbaElementow2;
  100. Console.WriteLine();
  101. Console.WriteLine("Suma 2: " + sumaKolejnych2.ToString() + "\nSrednia 2: " + sredniaKolejnych2.ToString());
  102.  
  103. // 3 tablica :
  104.  
  105. Console.ReadKey();
  106.  
  107.  
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement