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.
#include<stdio.h>intmain(){intn,total;//total number of rows and columnsscanf("%d",&n);total=n*2-1;for(introw=0;row<total;row++){for(intcol=1;col<=total;col++){if(row>total/2&&row<total-1){//second half patternif(row+col<total&&col<total/2)printf("%d",n--);elseif(col>row+1&&row<total-1)printf("%d",++n);elseprintf("%d",n);}elseif(col<=row&&row<=total/2)//first half patternprintf("%d",n--);elseif(col+row>=total+1&&row<=total/2)printf("%d",++n);elseprintf("%d",n);printf(" ");}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 worked for me