모든 답은 아래 교재를 참조합니다. 

 

싸니까 믿으니까 인터파크도서

생년월일 - 출생지 - 출간도서 0종 판매수 0권 (주)익스터디 대표이사, 두목넷 사무자동화 부분 대표 강사로 IT 자격증 분야에서 '왕두목'이라는 애칭으로 활발히 활동하고 있습니다. 경기공업대

book.interpark.com

10. 다음은 C언어로 작성된 선택정렬의 오름차순을 수행하는 프로그램이다. 빈 칸 (1) ~ (2)에 알맞은 표현을 쓰시오. 

#include <stdio.h>
int main()
{
int a[] = {95, 75, 85, 100, 50};
int i, j, temp;
int n = sizeof(a) / sizeof(int); // int n = 5;
for(i = 0; i < n-1; i++) {
for(j = i+1; j < n; j++) {
if(a[i] > a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(i = 0; i < 5; i++) {
printf("%d ", a[i]);
}
return 0;
}
---
50 75 85 95 100

 

11. 다음은 Java로 작성된 프로그램이다. 이를 실행한 결과를 쓰시오. 

public class Exam {
public static int[] makeArray(int n) {
int[] t = new int[n];
for(int i=0; i < n; i++){
t[i] = i*2;
System.out.printf("t[%d] = %d * 2 = %d\n", i, i, t[i]);
}
return t;
}
public static void main(String[] args) {
int[] a = makeArray(5);
for(int i = 0; i < a.length; i++) {
System.out.printf("the number == %d\n", i);
if(i%2 == 0) continue;
System.out.printf("the number == a[%d] == %d\n", i, a[i]);
// System.out.print(a[i] + " ");
}
}
}
----
t[0] = 0 * 2 = 0
t[1] = 1 * 2 = 2
t[2] = 2 * 2 = 4
t[3] = 3 * 2 = 6
t[4] = 4 * 2 = 8
the number == 0
the number == 1
the number == a[1] == 2
the number == 2
the number == 3
the number == a[3] == 6
the number == 4

12. 다음은 Java로 작성된 프로그램이다. 이를 실행한 결과를 쓰시오. 

public class Exam{
public static void main(String []args){
int a = 1, b = 43, c = 3;
int temp;
temp = a;
if(b > temp) temp = b;
if(c > temp) temp = c;
System.out.println(temp);
}
}
----
43

+ Recent posts