Last active
April 18, 2021 20:17
-
-
Save thepushkarp/b410d0bc9e34e9861e6c528810d19f76 to your computer and use it in GitHub Desktop.
Tech Hunt 2021 Level 5 Hint
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
// Notice the pattern? 👀 | |
#include <stdio.h> | |
int main() { | |
int k = 0, l = 0, m =5,n = 5, val = 1; | |
// | |
// | |
// | |
int a[m][n]; | |
while (k < m && l < n) { | |
for (int i = k; i < m; i++) | |
a[i][l] = val++; | |
l++; | |
for (int i = l; i < n; i++) | |
a[m-1][i] = val++; | |
m--; | |
for (int i = m-1; i >= k; i--) | |
a[i][n-1] = val++; | |
n--; | |
for (int i = n-1; i >= l; i--) | |
a[k][i]= val++; | |
k++; | |
} | |
for (int i = 0; i < 5; i++) { | |
for (int j = 0; j < 5; j++) | |
printf("%d\t", a[i][j]); | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment