Skip to content

Commit 03909a1

Browse files
committed
Added pattern programs
1 parent 40131ab commit 03909a1

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed

Pattern/pattern1.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# include <iostream>
2+
using namespace std;
3+
4+
int main(){
5+
cout<<"Enter the numbers of column"<<endl;
6+
int c;
7+
cin>>c;
8+
cout<<"Enter the number of rows"<<endl;
9+
int r;
10+
cin>>r;
11+
for(int i=1;i<=c;i++){
12+
for(int j=1;j<=r;j++){
13+
cout<<"*";
14+
}
15+
cout<<endl;
16+
}
17+
return 0;
18+
}

Pattern/pattern2.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* *****
2+
* *
3+
* *
4+
* *
5+
***** */
6+
7+
# include <iostream>
8+
using namespace std;
9+
10+
int main(){
11+
int i,j;
12+
for(i=1;i<=5;i++){
13+
for(j=1;j<=5;j++){
14+
if(i==1 || i==5){
15+
cout<<"*";
16+
}
17+
else{
18+
if(j==1 || j==5){
19+
cout<<"*";
20+
}
21+
else{
22+
cout<<" ";
23+
}
24+
}
25+
}
26+
cout<<endl;
27+
}
28+
}

Pattern/pattern3.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* for n = 5
2+
*****
3+
****
4+
***
5+
**
6+
* */
7+
8+
# include <iostream>
9+
using namespace std;
10+
11+
int main(){
12+
int n;
13+
cout<<"Enter a number"<<endl;
14+
cin>>n;
15+
for(int i=n;i>=1;i--){
16+
for(int j=1;j<=i; j++){
17+
cout<<"*";
18+
}
19+
cout<<endl;
20+
}
21+
return 0;
22+
}

Pattern/pattern4.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# include <iostream>
2+
using namespace std;
3+
4+
int main(){
5+
cout<<"Enter a number"<<endl;
6+
int n;
7+
cin>>n;
8+
int r = n;
9+
for(int i=1; i<=n; i++){
10+
for(int j=1; j<=n;j++){
11+
if(j>(n-i)){
12+
cout<<"*";
13+
}
14+
else{
15+
cout<<" ";
16+
}
17+
}
18+
cout<<endl;
19+
}
20+
}

Pattern/pattern5.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* for n = 6
2+
1
3+
22
4+
333
5+
4444
6+
55555
7+
666666 */
8+
9+
# include <iostream>
10+
using namespace std;
11+
12+
int main(){
13+
cout<<"Enter a number"<<endl;
14+
int n;
15+
cin>>n;
16+
for(int i =1; i<=n;i++){
17+
for(int j=1; j<=i; j++){
18+
cout<<i;
19+
}
20+
cout<<endl;
21+
}
22+
}

Pattern/pattern6.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* for n = 5
2+
1
3+
2 3
4+
4 5 6
5+
7 8 9 10
6+
11 12 13 14 15 */
7+
8+
# include <iostream>
9+
using namespace std;
10+
int main(){
11+
int n;
12+
int k =1;
13+
cout<<"Enter a number"<<endl;
14+
cin>>n;
15+
for(int i=1; i<=n; i++){
16+
for(int j=1; j<=i; j++){
17+
cout<<k<<" ";
18+
k++;
19+
}
20+
cout<<endl;
21+
}
22+
int s;
23+
cin>>s;
24+
}

0 commit comments

Comments
 (0)