1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| class Utile{
public static int fac(int a){
if(a<=1) return 1;
else return a*fac(a-1);
}
public static int comb(int r, int t){
int y = fac(t)/fac(r)*fac(t-r);
return y;
}
public static int comb1(int p, int n)
{ if((p==n)&&(p==0)) return 1;
else return comb(p-1,n-1)+comb(p-1,n);
}
}
public class trianglePascal
{ public static void main(String[] args)
{ int N;
System.out.print("entrer l'ordre auquel vous voullez determiner les coefficients de Pascal: ");
N = Clavier.lireInt(); System.out.println("\n");
int [][] t= new int[N][];
for(int n=0;n<N;n++)
{ for(int p=0;p<t[n].length;p++)
t[n][p] = Utile.comb1(p,n);
}for(int n=0;n<N;n++)
{ System.out.print ( " " + n + "| ") ;
for (int p=0 ; p<t[n].length ;p++)
System.out.print (t[n][p] + " ") ;
System.out.println ("\n") ;
}
}
} |
Partager