Pages

Sunday, March 30, 2025

Inverted & Rotated Half-pyramid pattern problem in C++

#include <iostream>
using namespace std;

// code to print inverted & rotated half-pyramid pattern
int main() {
    int n = 4;
    for(int i = 1; i <= n; i++){

        // spaces
        for(int j = 1; j <= n-i; j++){
            cout << " ";
        } // stars
        for(int j = 1; j <= i; j++){
            cout << "*";
        }

        cout << endl;        
    }

    return 0;

}

OUTPUT- * ** *** ****

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