Skip to content

Commit

Permalink
printing the pattern using loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudhakar17 committed Mar 29, 2020
1 parent 58271d9 commit 0033f2e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hackerrank/10_printing_patterns_using_loop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{

int n;
scanf("%d", &n);
int len = n*2 - 1;
for(int i=0;i<len;i++){
for(int j=0;j<len;j++){
int min = i < j ? i : j;
min = min < len-i-1 ? min : len-i-1;
min = min < len-j-1 ? min : len-j-1;
printf("%d ", n-min);
}
printf("\n");
}
return 0;
}

0 comments on commit 0033f2e

Please sign in to comment.