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

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