Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Cwiczenia_1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Console.WriteLine("Hello World!");
  10. }
  11. }
  12.  
  13. class Zadanie_4
  14. {
  15.  
  16. static void zadanie1()
  17. {
  18. int n;
  19. int i;
  20. int j; //przeksztalcanie wczytanego napisu na integer
  21. Console.Write("Podaj n:");
  22. if (!Int32.TryParse(Console.ReadLine(), out n) || n < 3 || n % 2 == 0)
  23. {
  24. Console.WriteLine("Błędna wartość. {n}");
  25. return;
  26. }//zaszyty mechanizm obslugi wyjatki
  27. for (i = 0; i < n; ++i)
  28. {
  29. Console.Write("* ");
  30. }
  31. Console.WriteLine();
  32. }
  33.  
  34. static double Odwrotnosc(double x)
  35. { double n;
  36.  
  37.  
  38. try
  39. { x = 1 / n; }
  40. catch (ArithmeticException e)
  41. { Console.WriteLine(e.Message); }
  42.  
  43. return x;
  44. }
  45.  
  46. static void Test_Zadanie_4()
  47. {
  48. double x;
  49. Console.Write("Podaj n:");
  50. double.TryParse(Console.ReadLine(), out x);
  51.  
  52. if (Math.Abs(x) < 0.001) {
  53. throw new ArithmeticException("Dzielenie przez 0!!!");
  54. }
  55.  
  56. Console.WriteLine(Odwrotnosc(x));
  57. }
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement