Voici un exemple d'un programme permettant d'afficher un triangle Pascal :
- #!/bin/csh
-
- @ I=0
- while ( $I <= 9 )
- @ J=0
- set CurrLine = ""
- while ( $J <= $I )
- @ R = $I * $J
- set CurrLine = "$CurrLine $R"
- @ J = $J + 1
- end
- echo $CurrLine
- @ I = $I + 1
- end
-
- # Dessin du triangle
- @ I=0
- while ( $I <= 12 )
- @ J=0
- set CurrLine = ""
- while ( $J <= (13 - $I) )
- set CurrLine = "$CurrLine _"
- @ J = $J + 1
- end
- @ J=0
- set CurrLine = "$CurrLine < "
- while ( $J <= ($I + $I) )
- set CurrLine = "$CurrLine x "
- @ J = $J + 1
- end
- echo $CurrLine "*"|sed 's/_/ /g'
- @ I = $I + 1
- end
on obtiendra le résultat suivant :
00 1
0 2 4
0 3 6 9
0 4 8 12 16
0 5 10 15 20 25
0 6 12 18 24 30 36
0 7 14 21 28 35 42 49
0 8 16 24 32 40 48 56 64
0 9 18 27 36 45 54 63 72 81
< x *
< x x x *
< x x x x x *
< x x x x x x x *
< x x x x x x x x x *
< x x x x x x x x x x x *
< x x x x x x x x x x x x x *
< x x x x x x x x x x x x x x x *
< x x x x x x x x x x x x x x x x x *
< x x x x x x x x x x x x x x x x x x x *
< x x x x x x x x x x x x x x x x x x x x x *
< x x x x x x x x x x x x x x x x x x x x x x x *
< x x x x x x x x x x x x x x x x x x x x x x x x x *
Voir également
Dernière mise à jour : Lundi, le 8 octobre 2018