Advertisement
Guest User

Untitled

a guest
Jun 7th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 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 Zadanie_1
  8. {
  9. class Program
  10. {
  11. static long Silnia(byte argument)
  12. {
  13. long rozwiazanie = 1;
  14. if (argument == 0 || argument == 1)
  15. {
  16. return 1;
  17. }
  18. else
  19. {
  20. for(byte i = argument; i>0; i--)
  21. {
  22. rozwiazanie = rozwiazanie * i;
  23. }
  24. return rozwiazanie;
  25. }
  26.  
  27. }
  28. static void Main(string[] args)
  29. {
  30. Console.Write("Podaj liczbę z której chcesz obliczyć silnię: ");
  31. long rozwiazanie;
  32. try
  33. {
  34. byte n;
  35. n = Convert.ToByte(Console.ReadLine());
  36. rozwiazanie = Silnia(n);
  37. Console.WriteLine(n + "! = " + rozwiazanie);
  38. }
  39. catch(Exception ex)
  40. {
  41. ConsoleColor bieżącyKolor = Console.ForegroundColor;
  42. Console.ForegroundColor = ConsoleColor.Red;
  43. Console.Error.WriteLine("Błąd: " + ex.Message);
  44. Console.ForegroundColor = bieżącyKolor;
  45. }
  46. Console.ReadKey();
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement