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);
// Complete the code to print the pattern.
int length = n*2-1;
//calculating the minimum distance of an element from for sides
int min;
for(int i =0; i<length; i++){
for(int j =0; j<length; j++){
if(i<=j){
min=i;
}else{min=j;}
if(min<=length-i-1){
min=min;
}else{min = length-i-1;} //i is the distance from top and length-i-1 is the distance from bottom
if(min<=length-j-1){ // j is te distance from left and legth-i-1 is the distance from right.
min=min;
}else{min = length-j-1;}
printf("%d ", n-min);
}
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 →
Solution 2 int main() {
}