📘 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

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

सारांश

  • हर row 1 से शुरू और खत्म; भीतरी values ऊपर की दो का योग।
  • Formula val = val*(i-j)/(j+1) हर entry निकालता है।
← Back to C++ Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n