rustandbone Developer

정보처리기사 실기 대비_파트10

정보처리기사 실기 대비

10. 프로그래밍 언어 활용

Section149 데이터 입출력

  1. 데이터 입력받아 화면이나 파일로 출력하는 것
    1. 헝가리안 표기법
      1. 변수명 작성 시 변수의 자료형을 알 수 있도록 자료형을 의미하는 문자를 포함하여 작성하는 방법(ex. i_InputA)
    2. 자료형
    3. C언어의 입출력 함수: scanf, printf
    4. Java의 입출력 함수: Scanner, nextInt, print, printf, printIn
    5. 서식 지정자와 제어 문자
      1. %d : 정수형 10진수
      2. %o : 정수형 8진수
      3. %x : 정수형 16진수
      4. %c : 문자의 입출력
      5. %s : 문자열의 입출력
      6. %f : 실수의 입출력
      7. \n : 커서를 다음 줄의 처음으로 이동
      8. \t : 커서를 일정 간격 띄움
      9. \0 : null 문자 출력
    6. 연산자와 우선순위
#include <stdio.h>
main() {
  int i, j, k;
  scanf("%d %d", &i, &j);
  k = i + j;
  printf("d\n", k);
}
import java.util.Scanner;
public class Test {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    System.out.printf("a * 3 = %d\n", a * 3);
    System.out.println("a / 2 = " + (a / 2));
    System.out.print("a - 1 = " + (a - 1));
    scan.close();
  }
}

Section150 제어문

#include <stdio.h>
main() {
  int score[] = {86, 53, 95, 76, 61};
  char grade;
  char str[] = "Rank";
  for(int i = 0; i < 5; i++) {
    switch (score[i] / 10) {
      case 10:
      case 9:
        grade = 'A';
        break;
      case 8:
        grade = 'B';
        break;
      case 7:
        grade = 'C';
        break;
      default: grade = 'F';
    }
    if(grade != 'F') {
      printf("%d is %c %s\n", i + 1, grade, str);
    }
  }
}
public class Test {
  public static void main(String[] args) {
    String str = 'agile';
    int x[] = {1, 2, 3, 4, 5};
    char y[] = new char[5];
    int i = 0;
    while(i < str.length()) {
      y[i] = str.charAt(i);
      i++;
    }
    for(int p : x) {
      i--;
      System.out.print(y[i]);
      System.out.print(p + " ");
    }
  }
}

Section151 포인터

  1. C언어에서는 변수의 주소를 포인터라 하고
  2. 포인터를 저장할 수 있는 변수를 포인터 변수라고 함
  3. 포인터는 출력할 수도
  4. 포인터가 가리키는 곳에 값을 저장하거나 읽어오는 등 다양한 조작 가능 => “주소를 제어할 수 있는 기능이 있다”
#include <stdio.h>
main() {
  int a = 50;
  int *b = &a;
  *b = *b + 20;
  printf("%d, %d\n", a, *b);
  char *s;
  s = "gilbut";
  for(int i = 0; i < 6; i += 2) {
    printf("%c, ", s[i]);
    printf("%c, ", *(s + i));
    printf("%s\n", s + i);
  }
}

Section152 사용자 정의 함수

  1. 사용자가 직접 만들어 사용하는 함수(함수 포인터, 재귀 함수)
#include <stdio.h>
main() {
  int (*pf)(int);
  pf = factorial;
  printf("%d", pf(3));
}

int factorial(int n) {
  if(n <= 1)
    return 1;
  else
    return n * factorial(n - 1);
}