Pages

Monday, March 31, 2025

Print the 0-1 Triangle Pattern in C++

 Print#include <iostream>

using namespace std;
int main() {
    // outer loop (rows) -> 1 to n
    for(int i = 1; i <= 5; i++){
        // numbers
        for(int j = i; j >= 1; j-- ){
            cout << j%2 << " ";
        }
        cout << endl;
    }
   
    return 0;
}


OUTPUT-
1 0 1 1 0 1 0 1 0 1 1 0 1 0 1

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...