C++ program to print the * pattern - coderforcoders

Search

Wednesday, 13 March 2019

C++ program to print the * pattern

#include<iostream>
using namespace std;
class pattern{
public:
int i,j;
void printPattern(int n)
{
cout<<"The pattern is\n";
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
cout<<"*\t";
}
cout<<endl;
}
}
};
int main()
{
pattern obj1;
int n;
cout<<"Please enter the number\n";
cin>>n;
obj1.printPattern(n);
cout<<endl;
}


Output 1:
Please enter the number
3
The pattern is
*
* *
* * *

Output 2:
Please enter the number
5
The pattern is
*
* *
* * *
* * * *
* * * * *

Output 3:
Please enter the number
7
The pattern is
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *



No comments:

Post a Comment