@nakov/

while-loop-factorial-csharp

C#

Factorial calculation using while-loop in C#

fork
loading
Files
  • main.cs
  • main.exe

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.39494826113484094","path":"main.cs","file":{"path":"main.cs","content":{"asEncoding":{"base64":"dXNpbmcgU3lzdGVtOwoKY2xhc3MgRmFjdG9yaWFsV2hpbGVMb29wRXhhbXBsZSB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpIHsKICAgICAgICBpbnQgbiA9IDU7CiAgICAgICAgaW50IGZhY3RvcmlhbCA9IDE7CiAgICAgICAgd2hpbGUgKG4gPiAxKQogICAgICAgIHsKICAgICAgICAgICAgZmFjdG9yaWFsID0gZmFjdG9yaWFsICogbjsKICAgICAgICAgICAgbi0tOwogICAgICAgIH0KICAgICAgICBDb25zb2xlLldyaXRlTGluZShmYWN0b3JpYWwpOwogICAgfQp9Cg=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;

class FactorialWhileLoopExample {
    public static void Main() {
        int n = 5;
        int factorial = 1;
        while (n > 1)
        {
            factorial = factorial * n;
            n--;
        }
        Console.WriteLine(factorial);
    }
}