/*
描述: 撰寫程式來生成並打印一個 4×4 的螺旋矩陣。螺旋矩陣是指從左上角開始填入數字1,沿著螺旋路徑填滿整個矩陣。
Description: Write a program to generate and print a 4×4 spiral matrix.
A spiral matrix starts by filling in the number 1 at the top-left corner, and continues filling in numbers along a spiral path until the entire matrix is filled.
Output:
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
*/
#include <stdio.h>
int main( ) {
int N = 4 ;
int num = 1 ;
int arr[ 4 ] [ 4 ] ;
int top = 0 , bottom = N - 1 , left = 0 , right = N - 1 ;
while ( top <= bottom && left <= right) {
// filling from left to right
// Write your code here
top++;
// filling from top to bottom
// Write your code here
right--;
// filling from right to left
if ( top <= bottom) {
// Write your code here
}
// filling from bottom to top
if ( left <= right) {
// Write your code here
}
}
for ( int i = 0 ; i < N; i++ ) {
for ( int j = 0 ; j < N; j++ ) {
}
}
}
LyoK5o+P6L+w77yaIOaSsOWvq+eoi+W8j+S+hueUn+aIkOS4puaJk+WNsOS4gOWAiyA0w5c0IOeahOieuuaXi+efqemZo+OAguieuuaXi+efqemZo+aYr+aMh+W+nuW3puS4iuinkumWi+Wni+Whq+WFpeaVuOWtlzHvvIzmsr/okZfonrrml4vot6/lvpHloavmu7/mlbTlgIvnn6npmaPjgIIKCkRlc2NyaXB0aW9uOiBXcml0ZSBhIHByb2dyYW0gdG8gZ2VuZXJhdGUgYW5kIHByaW50IGEgNMOXNCBzcGlyYWwgbWF0cml4LgpBIHNwaXJhbCBtYXRyaXggc3RhcnRzIGJ5IGZpbGxpbmcgaW4gdGhlIG51bWJlciAxIGF0IHRoZSB0b3AtbGVmdCBjb3JuZXIsIGFuZCBjb250aW51ZXMgZmlsbGluZyBpbiBudW1iZXJzIGFsb25nIGEgc3BpcmFsIHBhdGggdW50aWwgdGhlIGVudGlyZSBtYXRyaXggaXMgZmlsbGVkLgoKT3V0cHV077yaCiAxICAyICAzICA0IAoxMiAxMyAxNCAgNSAKMTEgMTYgMTUgIDYgCjEwICA5ICA4ICA3CiovCgoKI2luY2x1ZGUgPHN0ZGlvLmg+CmludCBtYWluKCl7CiAgICBpbnQgTiA9IDQ7CiAgICBpbnQgbnVtID0gMTsKICAgIGludCBhcnJbNF1bNF07CiAgICBpbnQgdG9wID0gMCwgYm90dG9tID0gTiAtIDEsIGxlZnQgPSAwLCByaWdodCA9IE4gLSAxOwoKICAgIHdoaWxlICh0b3AgPD0gYm90dG9tICYmIGxlZnQgPD0gcmlnaHQpIHsKICAgICAgICAvLyBmaWxsaW5nIGZyb20gbGVmdCB0byByaWdodAogICAgICAgIC8vIFdyaXRlIHlvdXIgY29kZSBoZXJlCiAgICAgICAgdG9wKys7CgogICAgICAgIC8vIGZpbGxpbmcgZnJvbSB0b3AgdG8gYm90dG9tCiAgICAgICAgLy8gV3JpdGUgeW91ciBjb2RlIGhlcmUKICAgICAgICByaWdodC0tOwoKICAgICAgICAvLyBmaWxsaW5nIGZyb20gcmlnaHQgdG8gbGVmdAogICAgICAgIGlmICh0b3AgPD0gYm90dG9tKSB7CiAgICAgICAgICAgIC8vIFdyaXRlIHlvdXIgY29kZSBoZXJlCiAgICAgICAgfQoKICAgICAgICAvLyBmaWxsaW5nIGZyb20gYm90dG9tIHRvIHRvcAogICAgICAgIGlmIChsZWZ0IDw9IHJpZ2h0KSB7CiAgICAgICAgICAgIC8vIFdyaXRlIHlvdXIgY29kZSBoZXJlCiAgICAgICAgfQogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTjsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBOOyBqKyspIHsKICAgICAgICAgICAgcHJpbnRmKCIlMmQgIiwgYXJyW2ldW2pdKTsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCJcbiIpOwogICAgfQp9