// http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2069&sca=20

# include <stdio.h>

# include <stdlib.h>


int main(void)

{

int** numArray = NULL; // 초기화

int row = 0x0; // 행

int col = 0x0; // 열

int i, j; // indx

int num = 0x1;


scanf("%d %d", &row, &col);


numArray = (int**)malloc(sizeof(int*)*row);


for (i = 0; i < row; i++)

{

*(numArray + i) = (int*)malloc(sizeof(int)*col);

}


// 값 초기화

for (i = 0; i < row; i++)

{

for (j = 0; j < col; j++)

{

*(*(numArray + i) + j) = 0x0;

}

}


// 값 대입

for (i = 0; i < row; i++)

{

for (j = 0; j < col; j++)

{

*(*(numArray + i) + j) = num;

num += 0x1;

}

}


// 값 출력

for (i = 0; i < row; i++)

{

for (j = 0; j < col; j++)

{

printf("%d", *(*(numArray + i) + j));

if (j != col - 1)

{

printf(" ");

}

}

printf("\n");

}

return 0;

}

'언어 > c언어' 카테고리의 다른 글

Naver_지식인  (0) 2018.09.25
네이버 지식인 답변  (0) 2018.09.14
네이버 지식인 문제 풀이  (0) 2018.06.15
네이버 지식인 문제 _02  (0) 2018.06.12
네이버 지식인 문제 _01  (0) 2018.06.12

https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=303569738



# include <stdio.h>
# include <string.h>
# define SIZE 40
void reverse(char* srcName, char* dstName);
int main(void)
{
char myName[SIZE]  = {0, }; //
char revName[SIZE] = {0, };
gets(myName);

reverse( myName, revName );
printf("%s\n", revName);
return 0;
} // end of main function 
void reverse(char* srcName, char* dstName)
{
int i;
int j = 0;
for (i = strlen(srcName)-1; i >= 0; i--)
{
*(dstName + j) = *(srcName + i);
j++;
//printf("%c", *(srcName + i));
}
} // end of reverse function




# include <stdio.h>
# define SIZE 20
# define TRUE 1
int strlengthRet(char*);
int main(void)
{
char s[SIZE] = {0, };

scanf("%s", s);
printf("%d\n", strlengthRet(s));
return 0;
} // end of main function
int strlengthRet(char* param)
{
char* indxChar = NULL;
unsigned int count = 0x0;
indxChar = param;
while (TRUE) 
{
if (*indxChar == '\0')
{
break;
}
else // *indxChar != '\0'
{
count += 1;
indxChar += 0x1;
}
}
return count;
} // end of strlengthRet


https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=303322772&page=1#answer2


# include <stdio.h>

int main(void)
{
int height = 0x0;
printf("높이 입력:  ");
scanf("%d", &height);

int num;
int numCnt = 0;
int decNum;
int i, k, l; // index

// 높이
for (i = 1; i <= height; i++)
{
decNum = 1;
num = 1;
// 공백
for (k = i; k < height; k++)
{
printf(" ");
}
// 증가 숫자
while (num <= i)
{
numCnt += 1; // 2
printf("%d", numCnt);
num += 1; // 2
}
// 감소 숫자
while (decNum < i)
{
numCnt -= 1; // 2
printf("%d", numCnt);
decNum += 1;
}
// 개행
printf("\n");
}
}
2018.06.12. 07:12


'언어 > c언어' 카테고리의 다른 글

http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2069&sca=20  (0) 2018.07.16
네이버 지식인 문제 풀이  (0) 2018.06.15
네이버 지식인 문제 _01  (0) 2018.06.12
네이버 지식인 문제  (0) 2018.03.19
naver 지식  (0) 2018.03.17

https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=303323830&page=1#answer2


# include <stdio.h>

typedef struct NumberPir
{
int height;
}NumberPir;
int main(void)
{
NumberPir data;
printf("높이 입력: ");
scanf("%d", &data.height);

int i, j, k, l;
for (i = 0; i < data.height; i++)
// 1:높이
// 2:공백
for (l = i; l < data.height - 1; l++)
{
printf(" ");
}
// 3:감소
for (j = i; j >= 1; j--)
{
printf("%d", j);
}
// 4:숫자 0
printf("%d", 0);
// 5:증가
for (k = 1; k <= i; k++)
{
printf("%d", k);
}
// 6:개행
printf("\n");
}
return 0;
}
2018.06.12. 06:13


'언어 > c언어' 카테고리의 다른 글

네이버 지식인 문제 풀이  (0) 2018.06.15
네이버 지식인 문제 _02  (0) 2018.06.12
네이버 지식인 문제  (0) 2018.03.19
naver 지식  (0) 2018.03.17
네이버 풀이  (0) 2018.03.11

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=297536290



# include <stdio.h>

void swap(char[], char[]);
int main()
{
int i;
char strV_a[7] = "D-WAR";
char strV_b[7] = "dragon";
swap(strV_a, strV_b);

    return 0;
}
void swap(char paramA[], char paramB[])
{
int i;
char temp[10] = { 0, };
i = 0;
while (paramA[i] != '\0')
{
temp[i] = paramA[i];
i++;
}

i = 0;
while (paramB[i] != '\0')
{
paramA[i] = paramB[i];
i++;
}
printf("paramA => %s\n", paramA);

i = 0;
while (temp[i] != '\0')
{
paramB[i] = temp[i];
i++;
}
printf("paramB => %s\n", paramB);
}


'언어 > c언어' 카테고리의 다른 글

네이버 지식인 문제 _02  (0) 2018.06.12
네이버 지식인 문제 _01  (0) 2018.06.12
naver 지식  (0) 2018.03.17
네이버 풀이  (0) 2018.03.11
stack  (0) 2018.03.04

naver 지식

언어/c언어2018. 3. 17. 17:08

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=297380724


# include <stdio.h>

# include <stdlib.h>

# define SIZE 15

# define ERROR 1

# define EMPTY 0

//-------------------------------------

typedef struct MovieSeat {

int seat[SIZE][SIZE]; // 15 X 15

}MovieSeat, *ptrMovieSeat;

//-------------------------------------

// $function prototype$

ptrMovieSeat retNode(); // #1.

void SeatMenu(); // #2.

void AllSeat(MovieSeat** s); // #3.

void ChoiceSeat(MovieSeat** s); // #4.

void ReserveSeat(MovieSeat** s); // #5.

//-------------------------------------

int main(void) {

ptrMovieSeat mySeat = retNode();

int choiceNumber = 0;

while (1) { // 무한 루프 

SeatMenu();

scanf("%d", &choiceNumber);

if (choiceNumber < 1 || choiceNumber > 4) {

printf("입력 에러\n");

}

else {

// choiceNumber >= 1 && choiceNumber <= 4

switch (choiceNumber) {

case 1: ChoiceSeat(&mySeat); break;

case 2: AllSeat(&mySeat); break;

case 3: ReserveSeat(&mySeat); break;

case 4: printf("프로그램 종료 \n");

goto end;

}

}

printf("<Enter>");

getch();

system("cls");

}

end:

free(mySeat); // 메모리 해제 

return 0;

} // end of main function 

ptrMovieSeat retNode() { // #1.

ptrMovieSeat node = (ptrMovieSeat)malloc(sizeof(MovieSeat));

if (node == NULL) {

fprintf(stderr, "malloc error ... !!!\n");

exit(ERROR);

}

else {

// 데이터 초기화

for (int i = 0; i < SIZE; i++) {

for (int j = 0; j < SIZE; j++) {

node->seat[i][j] = EMPTY;

}

}

return node;

}

} // end of retNode function 


void SeatMenu() { // #2.

printf("---------------------------------------\n");

printf(" >>>>> 좌석 예약 시스템 입니다. <<<<<< \n");

printf("1번 : 좌석 예약 <<<<<<<<<<<<<<<<<<<<< \n");

printf("2번 : 전체 좌석 보기 <<<<<<<<<<<<<<<<< \n");

printf("3번 : 예약된 좌석 정보 보기 <<<<<<<<<< \n");

printf("4번 : 예약 끝내기 <<<<<<<<<<<<<<<<<<< \n");

printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< \n");

printf("입력 :  ");

} // end of SeatMenu function 


void AllSeat(MovieSeat** s) { // #3.

printf("전체 좌석 정보 (0:비어 있는 좌석)/ (1:예약된 좌석) \n");

printf("====================================\n");


for (int i = 0; i <= SIZE; i++) {

for (int j = 0; j <= SIZE; j++) {

if (i == 0 && j == 0) {

printf("   ");

}

else {

// i != 0 or j != 0

if (i == 0 && j != 0) {

printf("%02d ", j);

}

else if (i!=0 && j == 0) {

printf("%02d ", i);

}

else { // i != 0 && j != 0

printf("%02d ", (*s)->seat[i-1][j-1]);

}

}

}

printf("\n");

}

printf("====================================\n");

} // end of AllSeat function 


void ChoiceSeat(MovieSeat** s) { // #4.

int rSeat; // 행

int cSeat; // 열

printf("예약 좌석 번호 (행)입력 :  ");

scanf("%d", &rSeat);

printf("예약 좌석 번호 (열)입력 :  ");

scanf("%d", &cSeat);


if ((**s).seat[rSeat-1][cSeat-1] != 0) {

printf("이미 예약된 좌석입니다. \n");

}

else {

if (rSeat <= 0 || rSeat > 15) {

printf("좌석의 범위가 맞지 않습니다. (1~15)\n");

}

else {

// 비어 있는 좌석이라면

// (**s).seat[rSeat][cSeat] == 0

(**s).seat[rSeat-1][cSeat-1] = 1;

}

}

} // end of ChoiceSeat function 


void ReserveSeat(MovieSeat** s) {

printf("이미 예약된 좌석들의 정보 입니다. \n");

printf("======================================================\n");

for (int i = 0; i < SIZE; i++) {

for (int j = 0; j < SIZE; j++) {

if ((** s).seat[i][j] == 1) {

printf("seat[%d][%d]\n",i+1, j+1);

}

}

}

printf("======================================================\n");

} // end of ReserveSeat function 

'언어 > c언어' 카테고리의 다른 글

네이버 지식인 문제 _01  (0) 2018.06.12
네이버 지식인 문제  (0) 2018.03.19
네이버 풀이  (0) 2018.03.11
stack  (0) 2018.03.04
오랜만에  (0) 2018.01.24

네이버 풀이

언어/c언어2018. 3. 11. 17:41

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=296972962


1번만 건드려봤다.


# include <stdio.h>

# define OR || 

int main(void) {

int number = 0x0;

scanf("%d", &number);

for (int i = 1; i <= number-1; i++) {

for (int j = 1; j <= number; j++) {

if (i == 1 OR i == number-1) {

printf("%d", number);

}

else {

if (j == 1 OR j == number) {

printf("%d", number);

}

else {

printf(" ");

}

}

}

printf("\n");

}

return 0;

}

'언어 > c언어' 카테고리의 다른 글

네이버 지식인 문제  (0) 2018.03.19
naver 지식  (0) 2018.03.17
stack  (0) 2018.03.04
오랜만에  (0) 2018.01.24
c언어 - 시저암호  (0) 2018.01.04

stack

언어/c언어2018. 3. 4. 14:01

/*

작성일 : 2018-03-04

작성자 : 김준현

주제  : 스택

*/

# include <stdio.h>

# include <stdlib.h>

# include <string.h>

# define STACK_LEN 10

# define ERROR_ 1

typedef struct _Stack

{

int eData[10];

int ebp;

int esp;

}Stack, *ptrStack;

// function prototype_______________________________________

ptrStack createNode();

void push(Stack** pNode);

int Is_Full(Stack** pNode);

void pop(Stack** pNode);

int Is_Empty(Stack** pNode);

void dataPrintf(Stack** pNode);

int main(void) 

{

ptrStack nodeStack = NULL;

nodeStack = createNode();

push(&nodeStack);

push(&nodeStack);

push(&nodeStack);

push(&nodeStack);

dataPrintf(&nodeStack);

pop(&nodeStack);

dataPrintf(&nodeStack);

pop(&nodeStack);

dataPrintf(&nodeStack);

free(nodeStack);

return 0;

} // end of main function 

ptrStack createNode()

{

ptrStack retNode = (ptrStack)malloc(sizeof(Stack));

int i; // index

if (retNode == NULL)

{

printf("malloc error !!!\n");

exit(ERROR_);

}

// data 초기화_______________________________________

retNode->ebp = -1;

retNode->esp = -1;

for (i = 0; i < STACK_LEN; i++)

{

retNode->eData[i] = 0;

}

return retNode;

} // end of createNode function

void push(Stack** pNode)

{

int InsertData = 0x0;

if (Is_Full(pNode))

{

// step_0] esp 이동 (extended stack pointer)

++(** pNode).esp;

// step_1] 삽입할 데이터 입력

printf("데이터 입력 :  ");

scanf("%d", &InsertData);

// step_2] 데이터 삽입

(** pNode).eData[(** pNode).esp] = InsertData;

return;

}

else

{

printf("Stack is full ... !!!\n");

return;

}

} // end of push function

int Is_Full(Stack** pNode)

{

if ((** pNode).esp == STACK_LEN-1)

{

return 0;

}

else

{ // (** pNode).esp != STACK_LEN-1

return 1;

}

} // end of Is_Full function 

void pop(Stack** pNode)

{

if (!Is_Empty(pNode))

{

printf("stack is empty ... !!!\n");

return;

}

else

{

printf("pop(%d)\n", (** pNode).eData[(** pNode).esp]);

--(** pNode).esp;

}

} // end of pop function 

int Is_Empty(Stack** pNode)

{

if ((** pNode).esp == (** pNode).ebp)

{

return 0;

}

else

{ // (** pNode).esp != (** pNode).ebp

return 1;

}

} // end of Is_Empty function 

void dataPrintf(Stack** pNode)

{

int i; // index

for (i = 0; i <= (** pNode).esp; i++)

{

printf("%d ", (** pNode).eData[i]);

}

printf("\n");

} // end of dataPrintf function 

'언어 > c언어' 카테고리의 다른 글

naver 지식  (0) 2018.03.17
네이버 풀이  (0) 2018.03.11
오랜만에  (0) 2018.01.24
c언어 - 시저암호  (0) 2018.01.04
유의 할것 strcmp  (0) 2017.12.23

오랜만에

언어/c언어2018. 1. 24. 22:59

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=293326675


# include <stdio.h>

# define T 1

int main(void) {

int num = 0;

while (T) {

scanf("%d", &num);

printf("%d", num);

if (num == 0) {

break;

}

else {

printf(" ");

}

}

printf("\n");

return 0;

}


=======================================================================================


# include <stdio.h>

# include <stdlib.h>

int main(void) {

int num = 0x0; // sizeof(int) = 4byte


while (1) {

printf("1부터 10까지의 수를 입력해주세요 :  ");

scanf("%d", &num);


// 예외처리

if (num + 48 >= 48 && num + 48 <= 57) {

printf("당신이 입력한 값은 => %d\n", num);

break;

}

else {

printf("반드시 1부터 10까지의 수를 입력하세요\n");

}

}


for (int i = 1; i <= num; i++) {

if (i % 3 == 0) {

printf("x");

}

else {

printf("%d", i);

}

if (i != num) {

printf(" ");

}

}

printf("\n");

return 0;

}

'언어 > c언어' 카테고리의 다른 글

네이버 풀이  (0) 2018.03.11
stack  (0) 2018.03.04
c언어 - 시저암호  (0) 2018.01.04
유의 할것 strcmp  (0) 2017.12.23
c언어 네이버  (0) 2017.12.19

//====================
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
# include <string.h>
# include <time.h>
# include <stdbool.h>
# define TEXT_LEN 80
# define ALPHA_LEN 26
# define ERROR 1
//====================
typedef struct _CEA {
 char plainText[TEXT_LEN]; // 평문
 char cipherText[TEXT_LEN]; // 암호문
 char decryptText[TEXT_LEN]; // 복호문
 char alpha[ALPHA_LEN];
 int secretKey;
}CEA, *ptrCea;
//====================
void init(CEA** param); // func.0
bool plainTextWrite(CEA** param); // func.1
void encryptText(CEA** param); // func.2
void generatorKey(CEA** param); // func.3
void decryptText(CEA** param); // func.4
//====================
int main(void) {
 ptrCea mNode = (ptrCea)malloc(sizeof(CEA));
 bool result; // true , false
 if (mNode == NULL) {
  printf("malloc error ... !!!\n");
  return ERROR;
 }
 else {
  // mNode != NULL
  result = plainTextWrite(&mNode);
  if (result == true) {
   generatorKey(&mNode);
   encryptText(&mNode);
   decryptText(&mNode);
   if (!strcmp(mNode->plainText, mNode->decryptText)) {
    printf("success ... !!!\n");
   }
   else {
    printf("fail ... !!!\n");
   }
  }
 }
 free(mNode);
 return 0;
} // end of main function
//====================
void init(CEA** param) { // func.0
 // data init
 strcpy((** param).plainText, "\0");
 strcpy((** param).cipherText, "\0");
 strcpy((** param).decryptText, "\0");
 strcpy((** param).alpha, "\0");
 (** param).secretKey = 0;
} // end of init function
//====================
bool plainTextWrite(CEA** param) { // func.1
 unsigned int i; // index
 printf("plainText input :  ");
 fgets((** param).plainText, TEXT_LEN, stdin);
 (** param).plainText[strlen((** param).plainText) - 1] = '\0';
 system("cls");
 printf("입력한 평문은 [%s] 입니다.\n", (** param).plainText);
 for (i = 0; i < strlen((** param).plainText); i++) {
  if ((** param).plainText[i] < (int)('A') || (** param).plainText[i] > (int)('Z')) {
   return false;
  }
 }
 return true;
} // end of plainTextWrite function
//====================
void encryptText(CEA** param) { // func.2
 int i,j,k = 0; // index
 int mv;
 char indx = (int)('A');
 for (i = 0; i < 26; i++) {
  (** param).alpha[i] = indx;
  indx++;
 } // end for_1
 for (i = 0; i < 26; i++) {
  printf("%c", (** param).alpha[i]);
  if (i != 25) {
   printf(" ");
  }
 } // end for_2
 printf("\n"); // 개행
 for (j = 0; j < strlen((** param).plainText); j++) {
  for (i = 0; i < 26; i++) {
   if ((** param).plainText[j] == (** param).alpha[i]) {
    mv = (i + (** param).secretKey) % 26;
    //printf("index => %d\n", i);
    (** param).cipherText[k] = (** param).alpha[mv];
    //printf("(** param).cipherText[%d] => %c\n", k,(** param).cipherText[k]);
    k++;
   }
  } // for_1
 } // for_2
 (** param).cipherText[k] = '\0';
 printf("cipherText is [%s]\n", (** param).cipherText);
} // end of encryptText function
//====================
void generatorKey(CEA** param) { // func.3
 srand((unsigned)time(NULL));
 (** param).secretKey = rand() % 26;
 printf("secretKey => %d\n", (** param).secretKey);
} // end of generatorKey function
//====================
void decryptText(CEA** param) { // func.4
 int i, k = 0; // index
 unsigned int j;
 int mv;
 for (j = 0; j < strlen((** param).cipherText); j++) {
  for (i = 0; i < 26; i++) {
   if ((** param).cipherText[j] == (** param).alpha[i]) {
    mv = (i - (** param).secretKey);
    if (mv < 0) {
     mv += 26;
    }
    else {
     mv %= 26;
    }
    //printf("index => %d\n", i);
    (** param).decryptText[k] = (** param).alpha[mv];
    //printf("(** param).cipherText[%d] => %c\n", k,(** param).cipherText[k]);
    k++;
   }
  } // for_1
 } // for_2
 (** param).decryptText[k] = '\0';
 printf("decryptText is [%s]\n", (** param).decryptText);
}// end of decryptText function

'언어 > c언어' 카테고리의 다른 글

stack  (0) 2018.03.04
오랜만에  (0) 2018.01.24
유의 할것 strcmp  (0) 2017.12.23
c언어 네이버  (0) 2017.12.19
풀이 네이버  (0) 2017.12.18