Advertisement
BloodMoonYTC

faktorialis-ciklus

Oct 24th, 2021
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System;
  2. using System.Runtime.ExceptionServices;
  3.  
  4. namespace vegtelen_ciklus
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n, i, faktorialis;
  11.  
  12.             while (true)
  13.             {
  14.                 Console.Write("Írj be egy egész számot: ");
  15.                 n = int.Parse(Console.ReadLine());
  16.  
  17.                 if (n < 0) break;
  18.  
  19.                 faktorialis = 1;
  20.                 for(i = 1; i <=n; i++)
  21.                 {
  22.                     faktorialis *= i;
  23.                 }
  24.                 Console.WriteLine("Az {0}! = {1}", i - 1, faktorialis);
  25.             }
  26.             Console.WriteLine("Vége");
  27.             Console.ReadLine();
  28.         }
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement