Permutation coefficient program

Here given code implementation process.

/*
    C program for
    Permutation coefficient program
*/
#include <stdio.h>

void permutationCoefficient(int n, int k)
{
	// Set initial value
	int p = 1;
	for (int i = n; i >= (n - k + 1); --i)
	{
		p = p *i;
	}
	// Display calculated results
	printf(" ( n = %d, k = %d ) : %d \n", n, k, p);
}
int main(int argc, char
	const *argv[])
{
	// Test samples
	permutationCoefficient(7, 3);
	permutationCoefficient(4, 2);
	return 0;
}

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12
/*
    Java Program for
    Permutation coefficient program
*/
public class Coefficient
{
	public void permutationCoefficient(int n, int k)
	{
		// Set initial value
		int p = 1;
		for (int i = n; i >= (n - k + 1); --i)
		{
			p = p * i;
		}
		// Display calculated results
		System.out.print(" ( n = " + n + ", k = " + k + " ) : " + p + " \n");
	}
	public static void main(String[] args)
	{
		Coefficient task = new Coefficient();
		// Test samples
		task.permutationCoefficient(7, 3);
		task.permutationCoefficient(4, 2);
	}
}

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12
// Include header file
#include <iostream>
using namespace std;
/*
    C++ Program for
    Permutation coefficient program
*/
class Coefficient
{
	public: void permutationCoefficient(int n, int k)
	{
		// Set initial value
		int p = 1;
		for (int i = n; i >= (n - k + 1); --i)
		{
			p = p *i;
		}
		// Display calculated results
		cout << " ( n = " << n << ", k = " << k << " ) : " << p << " \n";
	}
};
int main()
{
	Coefficient *task = new Coefficient();
	// Test samples
	task->permutationCoefficient(7, 3);
	task->permutationCoefficient(4, 2);
	return 0;
}

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12
// Include namespace system
using System;
/*
    Csharp Program for
    Permutation coefficient program
*/
public class Coefficient
{
	public void permutationCoefficient(int n, int k)
	{
		// Set initial value
		int p = 1;
		for (int i = n; i >= (n - k + 1); --i)
		{
			p = p * i;
		}
		// Display calculated results
		Console.Write(" ( n = " + n + ", k = " + k + " ) : " + p + " \n");
	}
	public static void Main(String[] args)
	{
		Coefficient task = new Coefficient();
		// Test samples
		task.permutationCoefficient(7, 3);
		task.permutationCoefficient(4, 2);
	}
}

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12
package main
import "fmt"
/*
    Go Program for
    Permutation coefficient program
*/

func permutationCoefficient(n, k int) {
	// Set initial value
	var p int = 1
	for i := n ; i >= (n - k + 1) ; i-- {
		p = p * i
	}
	// Display calculated results
	fmt.Print(" ( n = ", n, ", k = ", k, " ) : ", p, " \n")
}
func main() {

	// Test samples
	permutationCoefficient(7, 3)
	permutationCoefficient(4, 2)
}

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12
<?php
/*
    Php Program for
    Permutation coefficient program
*/
class Coefficient
{
	public	function permutationCoefficient($n, $k)
	{
		// Set initial value
		$p = 1;
		for ($i = $n; $i >= ($n - $k + 1); --$i)
		{
			$p = $p * $i;
		}
		// Display calculated results
		echo(" ( n = ".$n.", k = ".$k." ) : ".$p." \n");
	}
}

function main()
{
	$task = new Coefficient();
	// Test samples
	$task->permutationCoefficient(7, 3);
	$task->permutationCoefficient(4, 2);
}
main();

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12
/*
    Node JS Program for
    Permutation coefficient program
*/
class Coefficient
{
	permutationCoefficient(n, k)
	{
		// Set initial value
		var p = 1;
		for (var i = n; i >= (n - k + 1); --i)
		{
			p = p * i;
		}
		// Display calculated results
		process.stdout.write(" ( n = " + n + 
                             ", k = " + k + " ) : " + p + " \n");
	}
}

function main()
{
	var task = new Coefficient();
	// Test samples
	task.permutationCoefficient(7, 3);
	task.permutationCoefficient(4, 2);
}
main();

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12
#    Python 3 Program for
#    Permutation coefficient program
class Coefficient :
	def permutationCoefficient(self, n, k) :
		#  Set initial value
		p = 1
		i = n
		while (i >= (n - k + 1)) :
			p = p * i
			i -= 1
		
		#  Display calculated results
		print(" ( n = ", n ,", k = ", k ," ) : ", p,sep="" )
	

def main() :
	task = Coefficient()
	#  Test samples
	task.permutationCoefficient(7, 3)
	task.permutationCoefficient(4, 2)

if __name__ == "__main__": main()

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12
#    Ruby Program for
#    Permutation coefficient program
class Coefficient 
	def permutationCoefficient(n, k) 
		#  Set initial value
		p = 1
		i = n
		while (i >= (n - k + 1)) 
			p = p * i
			i -= 1
		end

		#  Display calculated results
		print(" ( n = ", n ,", k = ", k ," ) : ", p ," \n")
	end

end

def main() 
	task = Coefficient.new()
	#  Test samples
	task.permutationCoefficient(7, 3)
	task.permutationCoefficient(4, 2)
end

main()

Output

 ( n = 7, k = 3 ) : 210 
 ( n = 4, k = 2 ) : 12 
/*
    Scala Program for
    Permutation coefficient program
*/
class Coefficient()
{
	def permutationCoefficient(n: Int, k: Int): Unit = {
		// Set initial value
		var p: Int = 1;
		var i: Int = n;
		while (i >= (n - k + 1))
		{
			p = p * i;
			i -= 1;
		}
		// Display calculated results
		print(" ( n = " + n + ", k = " + k + " ) : " + p + " \n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Coefficient = new Coefficient();
		// Test samples
		task.permutationCoefficient(7, 3);
		task.permutationCoefficient(4, 2);
	}
}

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12
/*
    Swift 4 Program for
    Permutation coefficient program
*/
class Coefficient
{
	func permutationCoefficient(_ n: Int, _ k: Int)
	{
		// Set initial value
		var p: Int = 1;
		var i: Int = n;
		while (i >= (n - k + 1))
		{
			p = p * i;
			i -= 1;
		}
		// Display calculated results
		print(" ( n = ", n ,", k = ", k ," ) : ", p );
	}
}
func main()
{
	let task: Coefficient = Coefficient();
	// Test samples
	task.permutationCoefficient(7, 3);
	task.permutationCoefficient(4, 2);
}
main();

Output

 ( n =  7 , k =  3  ) :  210
 ( n =  4 , k =  2  ) :  12
/*
    Kotlin Program for
    Permutation coefficient program
*/
class Coefficient
{
	fun permutationCoefficient(n: Int, k: Int): Unit
	{
		// Set initial value
		var p: Int = 1;
		var i: Int = n;
		while (i >= (n - k + 1))
		{
			p = p * i;
			i -= 1;
		}
		// Display calculated results
		print(" ( n = " + n + ", k = " + k + " ) : " + p + " \n");
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Coefficient = Coefficient();
	// Test samples
	task.permutationCoefficient(7, 3);
	task.permutationCoefficient(4, 2);
}

Output

 ( n = 7, k = 3 ) : 210
 ( n = 4, k = 2 ) : 12


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved