코락 CoRock
코딩하는 락스타
코락 CoRock
  • 분류 전체보기 (394)
    • frameworks (19)
      • spring (19)
      • spring-boot (0)
      • testing (0)
    • languages (94)
      • java (39)
      • kotlin (0)
      • python (42)
      • r (13)
    • libraries (0)
    • programming (239)
      • android (13)
      • c (17)
      • cpp (22)
      • database (18)
      • design-pattern (4)
      • data-structures (11)
      • git (8)
      • hadoop (6)
      • html-css (7)
      • issue (4)
      • javascript (26)
      • jsp (34)
      • os (29)
      • php (6)
      • preferences (19)
      • etc (15)
    • discography (37)
      • k-pop (18)
      • pop (19)
    • blog (4)

블로그 메뉴

  • Programming
  • Java
  • JavaScript
  • Discography
  • K-Pop Songs
  • Pop Songs
  • Blog
  • Guestbook

공지사항

인기 글

태그

  • Spring
  • Android
  • CentOS
  • 자바스크립트
  • python
  • javascript
  • linux
  • r
  • 파이썬
  • jsp
  • oracle
  • Java

최근 댓글

최근 글

티스토리

반응형
hELLO · Designed By 정상우.
코락 CoRock

코딩하는 락스타

programming/c

주말숙제

2018. 1. 31. 17:24
반응형

1. 다음 문제의 출력 결과를 쓰시오. (10점)

(이 문제에서 double 타입의 크기는 8byte로가정, a : 0x1234)

voidmain()

{

    double a[10] = { 0 };

 

    printf("%p\n", a + 1);

    printf("%p\n", a + 2);

    printf("%p\n", a + 3);

    printf("%p\n", a - 1);

    printf("%p\n", a - 2);

}

1242 / 1250 / 1258/ 1226 / 1216

 

2. 다음과 같이 출력되도록 (////) 의 코드를 작성하시오. (10점)

1 01 0 1

0 10 1 0

1 01 0 1

0 10 1 0

1 0 1 0 1

 

intmain()

{

    intarr[5][5] = { 0 };

    int i,j;

 

(///////////////////)

 

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

    {

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

           printf("%3d", arr[i][j]);

       printf("\n");

    }

}

 

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

        {

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

               {

                       if (i == 0 || i == 2|| i == 4)

                       {

                              if (j == 0 || j == 2|| j == 4)

                              {

                                      arr[i][j]= 1;

                              }

                              else if (j == 1 || j ==3)

                              {

                                      arr[i][j]= 0;

                              }

                       }

                       if (i == 1 || i ==3)

                       {

                              if (j == 0 || j == 2|| j == 4)

                              {

                                      arr[i][j]= 0;

                              }

                              else if (j == 1 || j ==3)

                              {

                                      arr[i][j]= 1;

                              }

                       }

               }

        }

 

3. 다음 출력결과를 보고 IncrementArray() 함수를 작성하시오. (10점)

10  11   12   13  14

   11   12  13   14   15

   12   13  14   15   16

 

voidPrintArray(int arr[], int size)

{

    int i;

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

       printf("%5d", arr[i]);

    printf("\n");

}

voidmain()

{

    intarr[5] = { 10,11,12,13,14 };

 

   PrintArray(arr, 5);

   IncrementArray(arr, 5);

   PrintArray(arr, 5);

   IncrementArray(arr, 5);

   PrintArray(arr, 5);

 

}

 

void IncrementArray(int arr[], int size)

{

        int i;

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

        {

               arr[i] += 1;

        }

}

 

4. 다음 문제의 출력 결과를 쓰시오. (10점)

voidmain()

{

    int a =3;

    int f =0x4F;

 

    a = f<< 2 & 0x4F;

 

    printf("%x\n", a);

}

7c

 

5. 다음 ptr을 이용하여 elppa 가 출력되도록 (//////)에 코드를 작성하시오. (10점)

void main(void)

{

 charfruit[] = "apple";

 char*ptr;

 

 ptr= fruit + strlen(fruit);

 

 (//////)

}

ptr = fruit +strlen(fruit);

while(--ptr >= fruit)

puts(ptr);

 

6. 다음 출력 결과는 모든 문자열을 소문자로 변환하는 LowerString() 함수의 결과를출력한 것이다. 다음 LowerString() 함수를 작성하시오. (10점)

programming world

voidmain()

{

    chararr1[20] = "ProgramMING";

    chararr2[20] = "World";

 

   LowerString(arr1);

   LowerString(arr2);

    printf("%s %s\n", arr1, arr2);

}

void LowerString(char*array)

{

   For(int i = 0; I < 20; i++)

   {

     while(array[i] >= 65 &&array[i] <= 90)

     {

        array[i] += 32;

     }

   }

}

 

7. 다음 출력 결과는 콜백함수가 참을 반환하면 buf의해당 문자를 삭제하는 DeleteChar() 함수의 기능을 활용하여buf의 결과를 출력한 것이다. 다음 DeleteChar()함수를작성하시오. (20점)

 

ABCEFGIK

 

intCallbackFunc(char c)

{

    return c == 'D' || c == 'H'|| c == 'J';

}

voidmain()

{

    charbuf[100] = "ABCDEFGHIJK";

   DeleteChar(buf, CallbackFunc);

 

    printf("%s\n", buf);

}

 

 

 

8. 다음 출력 결과는 3개의 원소를 스택에 입력하고 출력한 결과이다. 스택의 초기화, 마무리 함수, 원소를입력하고 출력하기 위한 함수(InitStack(), UninitStack(), Push(), Pop())를작성하시오. (10점)

300

200

100

 

voidmain()

{

    intst[100];

    int top= 0;

 

   InitStack(st, &top);

    Push(st,&top, 100);

    Push(st,&top, 200);

    Push(st,&top, 300);

 

    printf("%d\n", Pop(st, &top));

    printf("%d\n", Pop(st, &top));

    printf("%d\n", Pop(st, &top));

   UninitStack(st, &top);

}

 

void Push(int *st, int *top, int a)

{

        if (*top >= 99)

        {

               printf("Overflow!\n");

        }

        st[++(*top)] = a;

        return a;

}

 

int Pop(int *st, int *top)

{

        if (*top < 0)

        {

               printf("Undeflow!");

        }

        return st[(*top)--];

}

 

void initStack(int *st, int *top)

{

        *top = -1;

}

 

void UninitStack(int *st, int *top)

{

        int i;

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

        {

               st[i] = 0;

        }

}

 

9. 다음은 strTable의 문자열을 출력한 결과다. PrintForwardString() 함수는 strTable의 문자열을 순서대로 출력하며 PrintBackwardString() 함수는 strTable의 문자열을반대 순서대로 출력하는 함수다. 두 함수를 작성하시오. (10점)

 

123  234  345 678  789

789  678  345 234  123

voidmain()

{

    char*strTable[5] = { "123","234","345","678","789" };

 

   PrintForwardString(strTable);

    printf("\n");

   PrintBackwardString(strTable);

}

 

voidPrintfForwardString(char **st)

{

        int i;

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

        {

               printf("%s\t", st[i]);

        }

}

 

voidPrintfBackwardString(char **st)

{

        int i;

        for (i = 4; i >=0; i--)

        {

               printf("%s\t", st[i]);

        }

}


반응형
저작자표시 비영리 변경금지
    'programming/c' 카테고리의 다른 글
    • String Class
    • Inheritance
    • [Algorithm] Baby Gin
    • [Core C] Functions (함수)
    코락 CoRock
    코락 CoRock
    A COder dreaming of being a ROCKstar

    티스토리툴바