Guest User

kalkulator

a guest
Dec 23rd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp4
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int wyjscie = 1;
  10.  
  11. while (wyjscie==1)
  12. {
  13. Console.WriteLine("1. Dodawanie");
  14. Console.WriteLine("2. Odejmowanie");
  15. Console.WriteLine("3. Mnożenie");
  16. Console.WriteLine("4. Dzielenie");
  17. Console.WriteLine("5. Potęgowanie Math.pow");
  18. Console.WriteLine("6. Potęgowanie własne");
  19. Console.WriteLine("7. Silnia");
  20. Console.WriteLine("8. Pole Kwadratu");
  21. Console.WriteLine("9. Pole Prostokąta");
  22. Console.WriteLine("10. Pole trójkata");
  23. Console.WriteLine("11. Objętość prostopadłościanu");
  24. Console.WriteLine("12. Wyjście");
  25. int wybor = int.Parse(Console.ReadLine());
  26. Console.Clear();
  27.  
  28. if (wybor == 12) { break; }
  29. else if (wybor == 7) { Console.WriteLine("Z jakiej liczby chcesz obliczyć silnie?:"); int c = int.Parse(Console.ReadLine()); int wynik = silnia(c); Console.WriteLine(wynik); }
  30. else if (wybor == 8) { Console.WriteLine("Podaj długość boku kwadratu:"); int bok = int.Parse(Console.ReadLine()); int wynik = mnozenie(bok, bok); Console.WriteLine("Pole kwadratu to: " + wynik + "^2"); }
  31. else if (wybor == 9)
  32. {
  33. Console.WriteLine("Podaj długość pierwszego boku:"); int bok1 = int.Parse(Console.ReadLine());
  34. Console.WriteLine("Podaj długość drugiego boku:"); int bok2 = int.Parse(Console.ReadLine()); int wynik = mnozenie(bok1, bok2); Console.WriteLine(wynik);
  35. }
  36. else if (wybor == 10) { Console.WriteLine("Podaj długość boku:"); double boka = double.Parse(Console.ReadLine()); Console.WriteLine("Podaj długość wysokości trójkąta:"); double h = double.Parse(Console.ReadLine()); double wynik = trojkat(boka, h); Console.WriteLine("Pole trójkąta to: " + wynik + "^2"); }
  37. else if (wybor == 11) { Console.WriteLine("Podaj długość pierwszego boku:"); int bok1 = int.Parse(Console.ReadLine()); Console.WriteLine("Podaj długośc drugiego boku:"); int bok2 = int.Parse(Console.ReadLine()); Console.WriteLine("Podaj wysokość:"); int wys = int.Parse(Console.ReadLine()); int wynik = prostopadloscian(bok1, bok2, wys); Console.WriteLine("Objętość prostopadłościanu to: " + wynik); }
  38. else if (wybor == 5|| wybor == 6)
  39. {
  40. Console.WriteLine("Z jakiej liczby chcesz policzyć potęgę? :");
  41. int d = int.Parse(Console.ReadLine());
  42. Console.WriteLine("Jaki ma być wykładnik? :");
  43. int e = int.Parse(Console.ReadLine());
  44. if (wybor == 5) { double wynik = potegowanie1(d, e); Console.WriteLine(wynik); }
  45. if (wybor == 6) { int wynik = potegowanie2(d, e); Console.WriteLine(wynik); }
  46. }
  47. else if (wybor == 1 || wybor == 2 || wybor == 3 || wybor == 4)
  48. {
  49. Console.WriteLine("Podaj pierwszą liczbę: ");
  50. int a = int.Parse(Console.ReadLine());
  51. Console.WriteLine("Podaj drugą liczbę: ");
  52. int b = int.Parse(Console.ReadLine());
  53. if (wybor == 1) { int wynik = dodawanie(a, b); Console.WriteLine(wynik); }
  54. if (wybor == 2) { int wynik = odejmowanie(a, b); Console.WriteLine(wynik); }
  55. if (wybor == 3) { int wynik = mnozenie(a, b); Console.WriteLine(wynik); }
  56. if (wybor == 4)
  57. { if (b == 0) { Console.WriteLine("nie dziel przez zero"); } else { int wynik = dzielenie(a, b); Console.WriteLine(wynik); } }
  58. }
  59. Console.WriteLine();
  60.  
  61. Console.ReadKey();
  62. Console.Clear();
  63. }
  64. }
  65.  
  66. static int dodawanie(int a, int b)
  67. { return a + b; }
  68. static int odejmowanie(int a, int b)
  69. { return a - b; }
  70. static int mnozenie(int a, int b)
  71. { return (a * b); }
  72. static int dzielenie (int a, int b)
  73. { return a / b; }
  74. static double potegowanie1 (double d,double e)
  75. { return Math.Pow(d, e); }
  76. static int potegowanie2 (int d, int e)
  77. { if (e <= 0)
  78. Console.WriteLine("1");
  79. int i = 1;
  80. int c = 1;
  81. for (i=1; i<=e;i = i++)
  82. {
  83. c = c * d;
  84. i = i + 1;
  85. }
  86. if (e > 0)
  87. Console.WriteLine();
  88. return c;
  89. }
  90. static int silnia(int c)
  91. { int i = 1;
  92. int d = 1;
  93. for (i=1;i<=c;i++)
  94. { d = d * i; }
  95. Console.WriteLine();
  96. return d;
  97. }
  98. static double trojkat (double a,double b)
  99. { double c = 0.5;
  100. a = a * c;
  101. return a * b;
  102. }
  103. static int prostopadloscian(int a,int b,int c)
  104. { return a * b * c; }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment