HomeCSharpC# Program to Find nPr

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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...