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

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...