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.
int n;
scanf("%d", &n);
int k = 2*n-1;
int temp = n; int c;
int store[k+1][k+1];
// Complete the code to print the pattern.
for ( int i = 0; i < k; i++){
n =temp;
c=0;
for (int j = 0; j<k; j++){
if(i+j<=k-1)
{if(c!=i )
{
printf("%d ",n);
store[i][j]=n;
c++;
n--;}
else {printf("%d ",n);
store[i][j]=n;}}
else { if (k-i-1 <=n && k-j-1 <= n){
printf("%d ",store[k-i-1][k-j-1]);
store[i][j]= store[k-i-1][k-j-1];}
else{
if (i<=j){printf("%d ",store[i][k-j-1]);
store[i][j]= store[i][k-j-1];}
else if(1==1){printf("%d ",store[k-i-1][j]);
store[i][j]= store[k-i-1][j];}
//for error cells
else {printf("(%d,%d)",i,j);
// printf("%d ", store[i][]);
}}
}
}
Took me 2 days to figure out! Happy Learning!
printf("\n");}
return 0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Printing Pattern Using Loops
You are viewing a single comment's thread. Return to all comments →
include
include
include
include
int main() {
return 0;}