Pattern Question (stars pattern in descending order) with source code and small explanation 03 || Print pattern using c++ with 5 rows and 5 columns

Here I am going to print following pattern using c plus plus language in pattern question 






ALGORITHM FOR PRINTING STAR PATTERN IN DESCENDING ORDER :

  1. header file include
  2. use namespace which standard in c plus plus
  3. Program's starting point : main() function
  4. declared two variable a, b
  5. get input of variable a,b
  6. use for loop for row till a
  7. use again for loop for column till b-(i-1) , here suppose b = 5 and i = 1 Now for first row where i=1 is running till 5-(1-1)=5 five. like this our loop work if i = 2 than loop will go through 5-(2-1)=4 four and so on.
  8. print * stars using cout 
  9. break line using line break endl after completing row.
  10. return 0 to show that there is no error in the program.
YOU CAN COPY THIS CODE AS WELL !

#include <iostream>
using namespace std;

int main(){
    int a , b;
    cin>>a>>b;

    for (int i = 1; i <= a; i++)
    {
        for (int j = 1; j <= b-(i-1); j++)
        {
           cout<<"* ";
        }
        cout<<endl;
    }
     return 0;
}

Comments