-
Notifications
You must be signed in to change notification settings - Fork 37
/
Butterfly Pattern.cpp
44 lines (36 loc) · 1011 Bytes
/
Butterfly Pattern.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//C++ program to print butterfly pattern
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cout<<"Enter the number of rows: "<<endl;
cin>>n;
//for upper half
for(int i=1; i<=n; i++){
//for printing starting pattern
for(int j=1; j<=i; j++)
cout<<"*";
//for printing spaces in between pattern
for(int j=1; j<=2*(n-i); j++)
cout<<" ";
//for print ending pattern
for(int j=1; j<=i; j++)
cout<<"*";
//provide next line
cout<<endl;
}
//for lower half
for(int i=n; i>=1; i--){
//for printing starting pattern
for(int j=1; j<=i; j++)
cout<<"*";
//for printing spaces
for(int j=1; j<=2*(n-i); j++)
cout<<" ";
//for printing ending pattern
for(int j=1; j<=i; j++)
cout<<"*";
cout<<endl;
}
return 0;
}