|
Voici un exemple d'une classe permettant d'afficher un triangle Pascal écrit en C# (C Sharp):
using System;
using System.Collections.Generic;
using System.Text;
namespace triangle
{
class Program
{
static void Main(string[] args)
{
// Triangle de nombre de Pascal
for ( int i = 0; i < 10; i++) {
for ( int j =0; j <= i; j++) {
Console.Write(" "+j*i);
}
Console.WriteLine();
}
// Dessin Triangle
for ( int i = 0; i < 13; i++) {
for ( int j = 0; j <= 13-i; j++) Console.Write(" ");
Console.Write("< ");
for ( int j = 0; j <= i+i; j++) Console.Write("x ");
Console.WriteLine("*");
}
}
}
}
|
on obtiendra le résultat suivant:
0
0 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
Science - Mathématique
|
|
| Dernière mise à jour: Vendredi, le 10 mars 2006 |