Advertisement
Dwight240

Untitled

Jun 7th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 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)
  15.             {
  16.                 Console.WriteLine("Podana wartość powinna być większa od 0 bądź równa 0");
  17.                 return 0;
  18.             }
  19.             else if (argument == 0 || argument == 1)
  20.             {
  21.                 return 1;
  22.             }
  23.             else
  24.             {
  25.                 for (byte i = argument; i > 0; i--)
  26.                 {
  27.                     rozwiazanie = rozwiazanie * i;
  28.  
  29.                 }
  30.                 return rozwiazanie;
  31.             }
  32.  
  33.         }
  34.         static void Main(string[] args)
  35.         {
  36.             Console.WriteLine("Podaj liczbę z której chcesz obliczyć silnię: ");
  37.             byte n;
  38.             long rozwiazanie = 0;
  39.             bool isProperly = Byte.TryParse(Console.ReadLine(), out n);
  40.             if (isProperly && n<=20)
  41.             {
  42.                 rozwiazanie = Silnia(n);
  43.             }
  44.             else
  45.             {
  46.                 Console.WriteLine("Wartość spoza zakresu 0-255");
  47.             }
  48.             Console.WriteLine(rozwiazanie);
  49.             Console.ReadKey();
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement