6. 프로그래밍 언어 활용

정보처리기사 정보처리기사요약 프로그래밍언어 아스키코드 연산자

기본 문법 활용하기

프로그래밍을 위한 기본 사항 :star::star:

  • 아스키 코드

    10진수 부호 10진수 부호 10진수 부호
    0 NULL 65 A 97 a
    32 ‘ ‘(Space) 66 B 98 b
    48 0 67 C 99 c
    49 1 68 D 100 d

변수 활용 :star::star::star:

  • 식별자 표기법: 카멜 표기법, 파스칼 표기법, 스네이크 표기법, 헝가리안 표기법

연산자

  • 연산자 우선순위: 감 연산자, 술 연산자, 프트 연산자, 계 연산자, 트 연산자, 리 연산자, 항 연산자, 입 연산자 증산시 관비 논삼대

기출 문제 :star::star::star::star::star:

#include <stdio.h>
void main() {
	// Bubble Sort
	int i, j;
	int temp;
	int a[5] = {75, 95, 85, 100, 50};

	for(i = 0; i < 4; i++) {
		for(j = 0; j < 4 - i) {
			if(a[j] > a[j + 1]) {
				temp = a[j];
				a[j] = a[j + 1];
				a[j + 1] = temp;
			}
		}
	}

	for(i = 0; i < 4; i++) {
		printf("%d", a[i]);
	}
}

정답: 50 75 85 95 100

public static void main(String[] args) {
	int i;
	int[] a = {0, 1, 2, 3};

	for(i = 0; i < 4; i++) {
		System.out.print(a[i] + " ");
	} 
}

정답: 0 1 2 3

public static void main(String[] args) {
	int i = 3;
	int k = 1;

	switch(i) {
		case 0:
		case 1:
		case 2:
		case 3: k = 0;
		case 4: k += 3;
		case 5: k -= 10;
		default: k--;
	}

	System.out.print(k);
}

정답: -8

a = {'일본', '중국', '한국'}
a.add('베트남')
a.add('중국')
a.remove('일본')
a.update({'홍콩', '한국', '태국'})
print(a)

정답: {’중국’, ‘한국’, ‘베트남’, ‘홍콩’, ‘태국’ }

class Parent {
	public void show() {
		System.out.println("Parent");
	}
}

class Child {
	public void show() {
		System.out.println("Child");
	}
}

public class Main {
	public static void main(String[] args) {
		Parent pa = ___ Child();
		pa.show():
	}
}

정답: 빈칸 = new, 결과 = Child

class A {
	private int a;

	public A(int a) {
		this.a = a;
	}

	public void display() {
		Syetem.out.println("a=" + a);
	}
}

class B extend A {
	public B(int a) {
		super(a);
		super.display();
	}
}

public class Main {
	public static void main(String[] args) {
		B obj = new B(10);
	}
}

정답: 10

#include <stdio.h>
void main() {
	int i = 0, c = 0;

	while(i < 10) {
		i++;
		c *= i;
	}

	printf("%d", c);
}

정답: 0

#include <stdio.h>
int r1() {
	return 4;
}

int r10() {
	return (30 + r1());
}

int r100() {
	return (200 + r10());
}

int main() {
	printf("%d", r100());
	return 0;
}

정답: 234

public static void main(String[] args) {
	int i = 0;
	int sum = 0;

	while(i < 10) {
		i++;
		if(i % 2 == 1) continue;
		sum += i;
	}
	System.out.println(sum);
}

정답: 30