曲径通幽论坛

标题: 反向输出数组内容 [打印本页]

作者: beyes    时间: 2009-9-8 23:02
标题: 反向输出数组内容
代码
#include <stdio.h>

int list [6] = {1, 2, 3, 4, 5, 6};    /*数组内容*/

/*-----------------------*/
/*递归数组反向输出函数   */
/*-----------------------*/
void invert_array (int j)
{
    if (j < 6) {
        /*递归链表输出函数调用*/
        invert_array (j + 1);
        printf ("[%d]", list[j]);
    }

   
}

int main ()
{
    int i;
    printf ("数组的内容:\n");
    for (i = 0; i < 6; i++)
        printf ("[%d]", list[i]);
    printf ("\n");
    printf ("递归输出数组的内容:\n");
    invert_array (0);
    printf ("\n");
   
    return (0);
}
运行与输出
beyes@linux-beyes:~/C/structer/recursion> ./stack_returen.exe
数组的内容:
[1][2][3][4][5][6]
递归输出数组的内容:
[6][5][4][3][2][1]





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2