You are on page 1of 2

Problema 9: Imprima la combinatoria de n tomados

de a r. Defina por lo menos una funcin.



Diagrama de Flujo














Cdigo en Java

import java.util.Scanner;

/**
* Imprima la combinatoria de n tomados de a r.
*
* @author Jhonny Felipez
* @version 1.0 27/04/2012
*
*/
public class Combinatoria {

public static long factorial(int n) {
long f = 1;
for (int i = 1; i <= n; i++)
f = f * i;
return f;
}

public static void main(String[] args) {
// Variables
int n, r;

// Entrada
Scanner lee = new Scanner(System.in);
System.out.print("Ingrese n = ");
n = lee.nextInt();
System.out.print("Ingrese r = ");
r = lee.nextInt();

// Proceso y Salida
System.out.printf("Combinatoria = %5.2f",
(double) factorial(n) /
(factorial(n - r) * factorial(r)));
}
}

You might also like