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.
There were definitely better ways to accomplish this...
#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>intmain(){intn;scanf("%d",&n);// Complete the code to print the pattern.intline_length=n*2-1;intline_counter=0;intreverse_point=line_length/2;intreverse_flag=0;intiteration_counter=0;while(iteration_counter!=line_length){for(intj=0;j<line_counter;j++){printf("%d ",n-j);}for(intk=0;k<line_length-line_counter*2;k++){printf("%d ",n-line_counter);}for(intl=0;l<line_counter;l++){printf("%d ",n-line_counter+l+1);}if(reverse_flag==1){line_counter--;}else{line_counter++;}if(line_counter>=reverse_point){reverse_flag++;}iteration_counter++;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 →
There were definitely better ways to accomplish this...