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

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...