Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. using System;
  2.  
  3. namespace zadd2
  4. {
  5. class Program
  6. {
  7. static long silnia(int n)
  8. {
  9. if (n < 2)
  10. return 1; //silnia z 0 i 1 wynosi 1
  11.  
  12. return n * silnia(n - 1); //wywołanie funkcji przez samą siebie ze zmniejszonym argumentem
  13. }
  14.  
  15. static void Main_rek()
  16. {
  17. Console.WriteLine("Podaj liczbe naturalna: ");
  18. var liczba = int.Parse(Console.ReadLine());
  19. Console.WriteLine(silnia(liczba));
  20.  
  21. }
  22.  
  23. static void Main()
  24. {
  25. Console.WriteLine("Podaj liczbe naturalna: ");
  26. var liczba = int.Parse(Console.ReadLine());
  27. var wynik = 1;
  28. while (liczba > 1)
  29. {
  30. wynik *= liczba;
  31. liczba--;
  32. }
  33.  
  34. Console.WriteLine(wynik);
  35.  
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement