We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Printing Pattern Using Loops
Printing Pattern Using Loops
Sort by
recency
|
998 Discussions
|
Please Login in order to post a comment
This is an easy solution based on make square legth ( 2*n-1 ) measuring the distance to the middle whose value is known =1 when i=j=n small example for n=3 so it willl be square of 3*2-1=5
Here is the logic that I used:
{n, n-1, n-2, ..., 1, ..., n-2, n-1, n}
.Those counters can be built by looping from
(n-1)
to(1-n)
, then for each value calculatingabs(value) + 1
.Here is amazing solution - HackerRank printing pattern using loops solution
This can be achieved by calculating the distance to the edge:
this is my code, i take this idea from a guy in comment :))
int main() {
}