Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- unsigned long long fib[100] = {0};
- void initialize_value()
- {
- fib[0] = 0;
- fib[1] = 1;
- for (int i = 2; i <= 100; ++i)
- fib[i] = fib[i - 1] + fib[i - 2];
- }
- int main()
- {
- int n;
- scanf("%d", &n);
- unsigned long long mat[n][n];
- initialize_value();
- int a = 0, b = n - 1;
- int index = 0;
- while (a <= b)
- {
- // Cạnh trên:
- for (int i = a; i <= b; ++i)
- {
- mat[a][i] = fib[index];
- ++index;
- }
- // Cạnh phải:
- for (int i = a + 1; i <= b; ++i)
- {
- mat[i][b] = fib[index];
- ++index;
- }
- // Cạnh dưới:
- for (int i = b - 1; i >= a; --i)
- {
- mat[b][i] = fib[index];
- ++index;
- }
- // Cạnh trái:
- for (int i = b - 1; i >= a + 1; --i)
- {
- mat[i][a] = fib[index];
- ++index;
- }
- // Giảm kích thước vòng:
- ++a; --b;
- }
- for (int i = 0; i < n; ++i)
- {
- for (int j = 0; j < n; ++j)
- {
- printf("%llu ", mat[i][j]);
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement