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 a,b,i,j,k,p,n,m[1000];
scanf("%d", &n);
// Complete the code to print the pattern.
k = (2*(n))-1;
a = k;
b = n;
//printf("%d",(n/2)+1);
for(i=1;i<=a;i++)
{
if (i<=(a/2)+1)
{
for(j=i;j<=k;j++)
{
m[j] = n;
}
for(p=1;p<=a;p++)
{
printf("%d ",m[p]);
}
printf("\n");
n--;
k--;
}
else if (i>(a/2)+1)
{
n++;
//k++;
// printf("%d\n",n);
// printf("%d\n",k);
for(j=i;j>=k;j--)
{
m[j] = n+1;
}
for(p=1;p<=a;p++)
{
printf("%d ",m[p]);
}
printf("\n");
k--;
}
Can anyone help me whats wrong with the code. Im getting segmentation fault when Im submitting it.
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Printing Pattern Using Loops
You are viewing a single comment's thread. Return to all comments →
int main() {
}