-
Notifications
You must be signed in to change notification settings - Fork 0
/
TriangleDePascal.cpp
62 lines (53 loc) · 1.15 KB
/
TriangleDePascal.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SARRITZU Peter
On W10
created :
12.01.2023
</La programmation a du bon>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <iostream> //entete de gestion des E/S
#include <string.h>
using namespace std;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fonction Triangle de Pascal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*
*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fonction Principale
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
int main()
{
int triangle[20][20] = { 0 };
int n;
int i, j;
cout << "Saisir n : ";
cin >> n;
//etape 1: Mettre des 1 dans la premièrer colonne (on s'arrête à n)
for (i = 0; i <= n; i++)
{
triangle[i][0] = 1;
}
//etape 2: Mettre des 1 sur la diagonale
for (i = 1; i <= n; i++)
{
triangle[i][i] = 1;
}
//etape 3: remplir les cases internes
for (i = 2; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
triangle[i][j] = triangle[i - 1][j] + triangle[i - 1][j - 1];
}
}
//etape 4: afficher le triangle
for (i = 0; i <= n; i++)
{
for (j = 1; j <= i; j++)
cout << triangle[i][j] << "\t";
cout << endl;
}
cin.get(); cin.ignore();
return EXIT_SUCCESS;
}