Pattern Question (print number pattern in c plus plus) with source code and small explanation 05 || 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 :
- header file include
- use namespace which standard in c plus plus
- Program's starting point : main() function
- declared two variable a
- get input of variable a
- use for loop for row till a
- use again for loop till current row number (i)
- to achieve this pattern we have to print row numbers only till column(j) which is equal to row number (i)
- print row number using cout
- break line using line break endl after completing row.
- return 0 to show that there is no error in the program.
#include <iostream>
using namespace std;
int main(){
int a;
cin>>a;
for (int i = 1; i <= a; i++)
{
for (int j = 1; j <= i; j++)
{
cout<<i;
}
cout<<endl;
}
return 0;
}
Comments
Post a Comment