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.
This can be achieved by calculating the distance to the edge:
#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>intmain(){intn;scanf("%d",&n);// Complete the code to print the pattern.intlen=2*n-1;inti,j;inthmin=0,vmin=0;intmin;for(i=0;i<n*2-1;i++){for(j=0;j<2*n-1;j++){vmin=i>n-1?len-1-i:i;hmin=j>n-1?len-1-j:j;min=hmin<vmin?hmin:vmin;printf("%d ",n-min);}printf("\n");}return0;}
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 →
This can be achieved by calculating the distance to the edge: