Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Zadanie_1
- {
- class Program
- {
- static long Silnia(byte argument)
- {
- long rozwiazanie = 1;
- if (argument < 0)
- {
- Console.WriteLine("Podana wartość powinna być większa od 0 bądź równa 0");
- return 0;
- }
- else if (argument == 0 || argument == 1)
- {
- return 1;
- }
- else
- {
- for (byte i = argument; i > 0; i--)
- {
- rozwiazanie = rozwiazanie * i;
- }
- return rozwiazanie;
- }
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Podaj liczbę z której chcesz obliczyć silnię: ");
- byte n;
- long rozwiazanie = 0;
- bool isProperly = Byte.TryParse(Console.ReadLine(), out n);
- if (isProperly && n<=20)
- {
- rozwiazanie = Silnia(n);
- }
- else
- {
- Console.WriteLine("Wartość spoza zakresu 0-255");
- }
- Console.WriteLine(rozwiazanie);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement