C# Program to Find nPr

In mathematics, nPr represents the number of permutations of n objects taken r at a time. In this task, we will write a C# program to find nPr.

Problem Statement

Write a C# program to find nPr. The program should take input from the user in the form of the values of n and r. The program should display the value of nPr as output.

C# Program to Find nPr

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Enter the value of n: ");
        int n = int.Parse(Console.ReadLine());

        Console.WriteLine("Enter the value of r: ");
        int r = int.Parse(Console.ReadLine());

        int nPr = 1;
        for (int i = n; i > n - r; i--)
        {
            nPr *= i;
        }

        Console.WriteLine("nPr: {0}", nPr);
    }
}

Input / Output

C# Program to Find nPr

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...