📘 Lesson · Lesson 81
Pascals Triangle
Pascals Triangle
Pascal's Triangle
💡 Note
Pascal's triangle is a triangle of numbers where each number is the sum of the two directly above it.
Program
C++
#include <iostream>
using namespace std;
int main() {
int rows = 5;
for (int i = 0; i < rows; i++) {
int val = 1;
for (int j = 0; j <= i; j++) {
cout << val << " ";
val = val * (i - j) / (j + 1);
}
cout << "\n";
}
return 0;
}Output:
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Summary
- Each row starts and ends with 1; inner values are sums of the two above.
- The formula val = val*(i-j)/(j+1) computes each entry.
Pascal's Triangle
💡 Note
Pascal's triangle numbers का त्रिकोण है जहाँ हर number ठीक ऊपर की दो संख्याओं का योग होता है।
Program
C++
#include <iostream>
using namespace std;
int main() {
int rows = 5;
for (int i = 0; i < rows; i++) {
int val = 1;
for (int j = 0; j <= i; j++) {
cout << val << " ";
val = val * (i - j) / (j + 1);
}
cout << "\n";
}
return 0;
}Output:
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
सारांश
- हर row 1 से शुरू और खत्म; भीतरी values ऊपर की दो का योग।
- Formula val = val*(i-j)/(j+1) हर entry निकालता है।