c#,npr,factorial,permutation

Ron 8/15/2016 0

This Code Shows How to Calculate nPr This C# Program Calculates nPr. Here There are n! (n factorial) permutations of n symbols. A r-permutation of n symbols is a permutation of r of them. There are n!/(n – r)! different r-permutations of n symbols.

C#
 /*
 * C# Program to Calculate nPr
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication40
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, r, per, fact, fact1;
            Console.WriteLine("Enter the Value of 'n' and 'r' to find the Permutation :");
            n = Convert.ToInt32(Console.ReadLine());
            r = Convert.ToInt32(Console.ReadLine());
            fact = n;
            for (int i = n - 1; i >= 1; i--)
            {
                fact = fact * i;
            }
            int number;
            number = n - r;
            fact1 = number;
            for (int i = number - 1; i >= 1; i--)
            {
                fact1 = fact1 * i;
            }
            per = fact / fact1;
            Console.WriteLine("Permutation : {0}",per);
            Console.ReadLine();
        }
    }
} 

/*
Here is the output of the C# Program: Enter the value of 'n' and 'r' to find the Permutation : 10 5 Permutation : 30240

*/

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments