Pages

Saturday, March 29, 2025

Inverted Star Patterns problem in C++

 #include <iostream>

#include <cmath>
using namespace std;
// inverted star pattern problem in C++

int main() {
    int n = 4;
   
    //outer loop
    for(int i=1; i <= n; i++){
        // inner loop
        for(int j = 1; j <= n-i+1; j++){
            // work
            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...