Created
September 2, 2018 13:03
-
-
Save sanket143/874c6e8b5f11531ae589bfe68e0b8170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
// Get Minimum Function | |
int min(int a, int b){ | |
if(a < b){ | |
return a; | |
} | |
return b; | |
} | |
int main(){ | |
int i, j; // Iterators | |
int i0; | |
int limit, limit_in; | |
int N = 5; // Box Size Param | |
for(i = 0; i < 2 * N - 1; i++){ | |
if(i >= N){ | |
i0 = 2 * (N - 1) - i; | |
} else { | |
i0 = i; | |
} | |
limit = 2 * N - 2 - i0; | |
for(j = 0; j < 2 * N - 1; j++){ | |
printf(" "); | |
if(j > 0){ | |
if(j <= limit){ | |
printf("%d", N - min(i0, j)); | |
limit_in = N - min(i0, j); | |
} else { | |
printf("%d", limit_in + 1); | |
limit_in = limit_in + 1; | |
} | |
} else { | |
printf("%d", N); | |
} | |
} | |
printf("\n"); | |
} | |
return 0; | |
} | |
/* | |
For N = 5 | |
Prints: | |
5 5 5 5 5 5 5 5 5 | |
5 4 4 4 4 4 4 4 5 | |
5 4 3 3 3 3 3 4 5 | |
5 4 3 2 2 2 3 4 5 | |
5 4 3 2 1 2 3 4 5 | |
5 4 3 2 2 2 3 4 5 | |
5 4 3 3 3 3 3 4 5 | |
5 4 4 4 4 4 4 4 5 | |
5 5 5 5 5 5 5 5 5 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment