언어/c언어

네이버 문제

파아랑새 2017. 10. 26. 21:10

#include <stdio.h>
#include <Windows.h>
#define R 2
#define C 10
typedef struct _Mat
{
 DWORD arry[2][10]; // 2행 10열
}Mat, *ptrMat;

PVOID createNode();
void __init__(Mat** param);
void __setting__(Mat** param);
void __dataPrintf__(Mat** param);


int main(void) {
 ptrMat node = NULL;
 node = createNode();
 __init__(&node);
 __setting__(&node);
 __dataPrintf__(&node);
 free(node);
 return 0;
} // end of main function


PVOID createNode()
{
 ptrMat pNode = (ptrMat)malloc(sizeof(Mat));
 return pNode;
} // end of createNode function
void __init__(Mat** param)
{
 if ((*param) == NULL)
 {
  __asm PUSH 1
  __asm CALL dword ptr[exit];
 }
 else // (*param) != NULL
 { // 초기화
  for (int i = 0; i < R; i++)
  { // row
   for (int j = 0; j < C; j++)
   { // col
    (** param).arry[i][j] = 0;
   }
  }
 }
} // end of __init__ function
void __setting__(Mat** param)
{
 int up_index   = 0;
 int down_index = 0;
 int i; // index
 int num;
 printf("숫자 입력 : ");
 scanf("%d", &num);
 for (i = 1; i <= num; i++)
 {
  // 1, 2, 3, 4, 5, ..., 20
  if (i % 2 == 1)
  {
   (** param).arry[0][up_index++]   = i;
  }
  else
  {
   (** param).arry[1][down_index++] = i;
  }
 }
} // end of __setting__ function
void __dataPrintf__(Mat** param)
{
 for (int i = 0; i <= 1; i++)
 {
  for (int j = 0; j < 10; j++)
  {
   printf("%2d", (** param).arry[i][j]);
  }
  printf("\n");
 }
} // end of __dataPrintf__ function