Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
factorial ncr + unique list
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here int t0,t1,t2,t3; List<int> num = new List<int>(new int[10]{1,2,3,4,5,6,7,8,9,10}); List<int> sub1 = num.GetRange(0,4); foreach (var obj in sub1) { Console.Write(obj+" "); } //Console.WriteLine(nCr(12,8)); //Console.WriteLine(Unique(num)); } public static bool Unique(List<int> t){ int count = 0; for (int i=0; i<t.Count()-1; i++){ for (int j=i+1; j<t.Count(); j++) { //Console.WriteLine(i + " " + j); if (!t[i].Equals(t[j])){ count++; } } } if (count.Equals(nCr(t.Count(),2))) { return true; } else return false; } public static int nCr(int n, int r) { return (Factorial(n)/Factorial(r))/Factorial(n-r); } public static int Factorial(int n) { if (n>0) { for (int i=n-1; i>1; i--) { n = n*i; } return n; } else if (n<0) throw new ArgumentOutOfRangeException("n","n should be non-zero"); else return 1; } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,16 sec, absolute running time: 0,09 sec, cpu time: 0,08 sec, average memory usage: 11 Mb, average nr of threads: 3, absolute service time: 0,27 sec
edit mode
|
history
|
discussion
1 2 3 4