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 || argument == 1)
- {
- return 1;
- }
- else
- {
- for(byte i = argument; i>0; i--)
- {
- rozwiazanie = rozwiazanie * i;
- }
- return rozwiazanie;
- }
- }
- static void Main(string[] args)
- {
- Console.Write("Podaj liczbę z której chcesz obliczyć silnię: ");
- long rozwiazanie;
- try
- {
- byte n;
- n = Convert.ToByte(Console.ReadLine());
- rozwiazanie = Silnia(n);
- Console.WriteLine(n + "! = " + rozwiazanie);
- }
- catch(Exception ex)
- {
- ConsoleColor bieżącyKolor = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Error.WriteLine("Błąd: " + ex.Message);
- Console.ForegroundColor = bieżącyKolor;
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement