Pattern Question (print number pattern in c plus plus) with source code and small explanation 06 || Print pattern using c++ with 5 rows and 5 columns

  Here I am going to print following pattern (  the number pattern ) using c plus plus language.







ALGORITHM FOR PRINTING STAR PATTERN IN ASCENDING ORDER OF ROWS :

  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 
  5. also initialize on variable count with value 0
  6. get input of variable a
  7. use for loop for row till a
  8. use again for loop till current row number (i) for  getting column.
  9. to achieve this pattern we have to print counter numbers in increasing order (like 1,2,3,4,5...) only till column(j) which is equal to row number (i)
  10. here we are using increament operator ++ for increasing value by one 1.
  11. print row number using cout 
  12. break line using line break endl after completing row.
  13. return 0 to show that there is no error in the program.

#include <iostream>
using namespace std;

int main(){
    int a ,count=1;
    cin>>a;

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

Comments