[C Primer Plus] #2 C 첫걸음

문연수·2022년 3월 3일
0

C Primer Plus

목록 보기
2/5
post-thumbnail

1. 복습 문제

1. C 프로그램을 구성하는 기본 모듈을 무엇이라 부르는가?

함수

2. 신택스 에러란 무엇인가? 영어와 C 언어에서 각각 하나씩 예를 들어라.

Synatx error 란 문법 에러를 의미한다.

  • 영어

I'm love you.

  • C 언어
printf("hello, world\n")

3. 시맨틱 에러란 무엇인가? 영어와 C 언어에서 각각 하나씩 예를 들어라.

Semantic error 란 문법 상의 오류는 없지만 그 내용에 논리적 모순이 있는 것을 의미한다.

  • 영어

My father is younger than me.

  • C 언어
if (x == 0)
	if (y == 0)
		error();
else {
	z = x + y;
	f (&z);
}

4. 초보 프로그래머가 다음과 같이 프로그램을 작성하여, 승인을 받겠다고 가져왔다. 어디가 잘못되었는지 꼬치꼬치 지적해 주어라.

#include <stdio.h>

int main(void)
{
	int s;
    
    s = 56;
    printf("1년은 %d 주에 해당한다", s);
    
    return 0;
}

5. 아래의 각 문장들은 완전한 프로그램의 일부라고 가정하자. 그렇다면 각각 무엇을 출력하겠는가?

A.

Baa Baa Baa Black Sheep.Have you any wool?
<newline>

B.

Begone!
0 creature of lard!

C.

What?
No
fish?
<newline>

D.

2 + 2 = 4

6. 다음 중 어느 것이 C 의 키워드인가?

intchar

7. 두 변수 wordslines 의 값을 어떻게 출력시켜야 결과가 다음과 같은 형식으로 나타나게 될까? 여기서 두 변수의 값은 각각 3020 과 350 이다.

There were 3020 words and 350 lines.

printf("There were %d words and %d lines\n", words, lines);

8. 다음과 같은 프로그램이 있다고 가정하자. 라인 7, 8, 9 가 실행된 후의 프로그램 상태를 말하라.

a = 5
b = 5

9. 다음과 같은 프로그램이 있다고 가정하자. 라인 7, 8, 9 가 실행된 후의 프로그램의 상태를 말하라.

x = 150
y = 15

2. 프로그래밍 연습

1.

#include <stdio.h>

int main(void)
{
	printf("문연수\n");
    printf("문\n연수\n");
    printf("문"); printf("연수\n");
    
	return 0;
}

2.

#include <stdio.h>

int main(void)
{
	printf("이름: 문연수\n");
    printf("주소: 전라북도 전주시 완산구 효자동 3가 1722-10번지 하남해비치 205호\n");
    
	return 0;
}

3.

#include <stdio.h>

int main(void)
{
	int year, month, day;
	int year_now = 2022;
	int total;

	year = 2000; month = 11; day = 30;
	total = (year_now - (year + 1)) * 365
	      + ((12 - month) * 30)
	      + (30 - day);

	printf("year: %d\tmonth: %d\n",
		year_now - year, total);

	return 0;
}

4.

#include <stdio.h>

void jolly_good(void);
void deny(void);

int main(void)
{
	jolly_good(); jolly_good(); jolly_good(); jolly_good();
	deny();

	return 0;
}

void jolly(void)
{
	printf("For he's a jolly good fellow!\n");
}

void deny(void)
{
	printf("Which nobody can deny!\n");
}

5.

#include <stdio.h>

void br(void);
void ic(void);

int main(void)
{
	br(); printf(","); ic(); printf("\n");
	ic(); printf(",\n");
	br(); printf("\n");

	return 0;
}

void br(void)
{
	printf("Brazil, Russia");
}

void ic(void)
{
	printf("India, China");
}

6.

#include <stdio.h>

int main(void)
{
	int toes = 10;

	printf("toes: %d\tsquare of toes: %d\tmultiple of toes: %d\n",
		toes, toes * toes, toes * 2);

	return 0;
}

7.

#include <stdio.h>

void smile(void)
{
	printf("Smile!");
}

int main(void)
{
	smile(); smile(); smile(); printf("\n");
	smile(); smile(); printf("\n");
	smile(); printf("\n");

	return 0;
}

8.

#include <stdio.h>

void two(void)
{
	printf("two\n");
}

void one_three(void)
{
	printf("one\n");
    two();
    printf("three\n");
}

int main(void)
{
	printf("starting now:\n");
	one_three();
    printf("done!\n");
    
	return 0;
}
profile
2000.11.30

0개의 댓글