C언어 콘서트 8장 프로그래밍(Programming) 풀이
본문 바로가기

프로그래밍/c언어 콘서트

C언어 콘서트 8장 프로그래밍(Programming) 풀이

 

2.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
 
double get_bigger(double , double );
 
int main(void) {
 
    double first, second;
 
    printf("실수를 입력하시오: ");
    scanf("%lf"&first);
 
    printf("실수를 입력하시오: ");
    scanf("%lf"&second);
    
    printf("더 큰수는 %lf입니다.", get_bigger(first, second));
 
    return 0;
}
 
double get_bigger(double x, double y){
    if (x > y)
        return x;
    else
        return y;
}
cs

 

4.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
 
void get_divisor(int);
 
int main(void) {
    
    int user;
 
    printf("약수를 찾을 정수 입력: ");
    scanf("%d"&user);
 
    get_divisor(user);
 
    return 0;
}
 
void get_divisor(int x) {
 
    int i;
 
    printf("%d의 약수 = ", x);
 
    for (i = 1; i <= x; i++)
    {
        if (x % i == 0)
            printf("%d ", i);
    }
}
cs

 

6.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
 
void ipower(intint);
 
int main(void) {
 
    int first, second;
 
    printf("계산할 정수 입력: ");
    scanf("%d %d"&first, &second);
 
    ipower(first, second);
 
    return 0;
}
 
void ipower(int x, int y) 
{
    int i, sum = 1;
 
    if (y == 0)
        printf("%d", 1);
    else 
    {
        printf("%d\n"1);
 
        for (i = 1; i <= y; i++)
        {
            sum = x * sum;
            printf("%d\n", sum);
        }
    }
}
cs

 

8.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <math.h>
 
void quad_eqn(doubledoubledouble);
 
int main(void)
{
    double first, second, third;
 
    printf("2차 방정식의 계수를 입력하시오:\n");
 
    printf("a: ");
    scanf("%lf"&first);
    printf("b: ");
    scanf("%lf"&second);
    printf("c: ");
    scanf("%lf"&third);
 
    quad_eqn(first, second, third);
 
    return 0;
}
 
void quad_eqn(double a, double b, double c)
{
    double sum1, sum2;
    double judge;
 
    judge = b * b - 4 * a * c;
 
    if (judge < 0)
        printf("근이 없습니다.");
    else
    {
        sum1 = (-+ sqrt(b * b - 4 * a * c)) / 2 * a;
        sum2 = (-- sqrt(b * b - 4 * a * c)) / 2 * a;
 
        printf("%lf\n", sum1);
        printf("%lf\n", sum2);
    }
 
}
cs

 

9.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
 
 
int coin() 
{
    int x = rand() % 2;
 
    return x;
}
 
int main(void)
{
    int i, result;
 
 
    do {
        printf("앞(0) 또는 뒤(1)를 선택하시오(종료는 -1): ");
        scanf("%d"&i);
 
        result = coin();
 
        if (i == -1)
            return 0;
        else if (result == i)
            printf("사용자가 이겼습니다.\n");
        else if (result != i)
            printf("컴퓨터가 이겼습니다.\n");
        
 
    } while (1);
 
    return 0;
}
cs

 

12.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
 
void show_digit(int);
 
int main(void)
{
    int user;
 
    printf("정수를 입력하시오: ");
    scanf("%d"&user);
 
    show_digit(user);
 
    return 0;
}
 
void show_digit(int x) {
    
    if (x > 10) {
        show_digit(x / 10);
        printf("%d ", x % 10);
    }
    else
        printf("%d ", x);
    
}
cs

 

제가만든 게임입니다! 도움이 되셨다면 평가 한번 부탁드립니다~

https://play.google.com/store/apps/details?id=com.attitudeproblem&hl=en_CA&gl=

 

교관님 몰래 춤추기 – Apps on Google Play

Avoid the instructor's eyes and dance! Please have fun while watching the instructor's fakes. Raise your stats and items to challenge the higher score!

play.google.com