-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPattenGenerator.cpp
More file actions
72 lines (68 loc) · 1011 Bytes
/
Copy pathPattenGenerator.cpp
File metadata and controls
72 lines (68 loc) · 1011 Bytes
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
/*
PATTERN CREATOR:
input: 7
output:
7777777
7666667
7655567
7654567
7655567
7666667
7777777
*/
int n,i,j;
cin>>n;
//will go till half (if odd then half+1)
for(i=0;i<=ceil(n/2);i++)
{
int k=n;
//count for number of times we need to decrease in a perticular row
//flag for: once started to increament value in row, not to decreament it again
int count=0,flag=0;
for(j=0;j<n;j++)
{
cout<<k;
//decreasing value
if(count<i && flag==0)
{
count++;
k--;
}
// time to increase the value
if(j!=0 && j-i>=0 && j>=n-1-i )
{
k++;
flag=1;
}
}
cout<<endl;
}
//to repeat the above procedure in reverse
for(i=(n-2-ceil(n/2));i>=0;i--)
{
int k=n;
int count=0,flag=0;
for(j=0;j<n;j++)
{
cout<<k;
if(count<i && flag==0)
{
count++;
k--;
}
if(j!=0 && j-i>=0 && j>=n-1-i )
{
k++;
flag=1;
count--;
}
}
cout<<endl;
}
return 0;
}