Pages

Sunday, March 30, 2025

Floyd's Pattern problem in C++

 #include <iostream>

using namespace std;

// floyd's triangle pattern problem
int main() {
    int n = 5;
    int num = 1;

    // outer loop - rows
    for(int i= 1; i<= n; i++){
        // inner loop - each rows
        for(int j =1; j <= i; j++){
            cout << num++ << " ";
        }
        cout << endl;
    }

    return 0;

}

OUTPUT-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...