LoginSignup
1
0

More than 5 years have passed since last update.

再帰関数

Posted at
1 / 2
test.c
#include <stdio.h>

void sub(int* dim, int dim_index, int* data, int y)
{
    int x_max = dim[dim_index];
    for(int x=0; x<x_max; x++)
    {
        int z = y * x_max + x;
        if(dim_index==0)
        {
            printf("data[%d]=%d\n",z,data[z]);
        }
        else
        {
            sub(dim, dim_index-1, data, z);
        }
    }
}

int main()
{
    int dim[] = {1,2,3,4};
    int size = 4;
    int data[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
    sub(dim, size-1, data, 0);
    return(0);
}


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0