Guest User

Untitled

a guest
Mar 27th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace NumbersOfTriangles
  8. {
  9. class NumbersOfTriangles
  10. {
  11. class Triangles
  12. {
  13. static int a, b, c, d;
  14. int TriangleSides = 3;
  15. int[] Values = { a, b, c, d };
  16.  
  17. public Triangles()
  18. {
  19. Console.WriteLine("Podaj długość boku a: ");
  20. a = Int32.Parse(Console.ReadLine());
  21.  
  22. Console.WriteLine("Podaj długość boku b: ");
  23. b = Int32.Parse(Console.ReadLine());
  24.  
  25. Console.WriteLine("Podaj długość boku c: ");
  26. c = Int32.Parse(Console.ReadLine());
  27.  
  28. Console.WriteLine("Podaj długość boku d: ");
  29. d = Int32.Parse(Console.ReadLine());
  30. }
  31.  
  32. public int AllTriangles()
  33. {
  34. int n = Values.Length;
  35. int k = TriangleSides;
  36. int nk = n - k;
  37.  
  38. int factorialN= 1;
  39. int factorialK= 1;
  40. int factorialNK=1;
  41.  
  42. int FactorialN()
  43. {
  44.  
  45. for (int i = 1; i <= n; i++)
  46. {
  47. factorialN *= i;
  48. }
  49.  
  50. return factorialN;
  51. }
  52.  
  53. int FactorialK()
  54. {
  55. for (int i = 1; i <= k; i++)
  56. {
  57. factorialK *= i;
  58. }
  59.  
  60. return factorialK;
  61. }
  62.  
  63. int FactorialNK()
  64. {
  65. for (int i = 1; i <= nk; i++)
  66. {
  67. factorialNK *= i;
  68. }
  69.  
  70. return factorialNK;
  71. }
  72.  
  73. int FN = FactorialN();
  74. int FK = FactorialK();
  75. int FnK = FactorialNK();
  76.  
  77. int NumberOfTriangles = FN / FK * FnK;
  78. return NumberOfTriangles;
  79. }
  80.  
  81. public int[,] DivisionOfTriangles()
  82. {
  83. int[,] Triangles = new int[AllTriangles(), TriangleSides];
  84. int x = 0;
  85.  
  86. for (int row = 0; row < Triangles.GetLength(0); row++)
  87. {
  88. for (int column = 0; column < Triangles.GetLength(1); column++)
  89. {
  90. if (column + x == 4)
  91. {
  92. x = -2;
  93. }
  94. if (row == 3 && column == 0)
  95. {
  96. x = 3;
  97. }
  98. else if (row == 3 && column != 0)
  99. {
  100. x = -1;
  101. }
  102.  
  103. Triangles[row,column] = Values[column + x];
  104. }
  105.  
  106. x++;
  107.  
  108. }
  109.  
  110. return Triangles; //jak zwrócić wypełnioną tablicę?
  111. }
  112.  
  113. static void Main(string[] args)
  114. {
  115. Triangles Triangles = new Triangles();
  116. Console.WriteLine(Triangles.DivisionOfTriangles()); //podupione łubudu
  117.  
  118. Console.ReadLine();
  119. }
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment