C++ program to print number pattern. - coderforcoders

Search

Wednesday, 13 March 2019

C++ program to print number 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<<i<<"\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
1
2 2
3 3 3

Output 2:
Please enter the number
5
The pattern is
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Output 3:
Please enter the number
7
The pattern is
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7



No comments:

Post a Comment