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

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

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

 

 

 

1.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
 
int get_array_sum(int *A, int size
{
    int i, sum = 0;
 
    for (i = 0; i < size; i++)
    {
        sum += A[i];
    }
 
    return sum;
}
 
int main(void)
{
    int data[10= { 123456789 };
 
    printf("배열 요소들의 합 = %d", get_array_sum(data, 10));
 
    return 0;
}
cs

 

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
#include <stdio.h>
 
void array_reverse(int* A, int size)
{
    int i;
 
    for (i = 1; i <= size; i++) {
        printf("%d ", A[size - i]);
    }
}
 
int main(void)
{
    int user[5];
    printf("다섯개의 정수를 입력하시오: ");
 
    scanf("%d %d %d %d %d"&user[0], &user[1], &user[2], &user[3], &user[4]);
 
    printf("역순: ");
 
    array_reverse(user, 5);
 
    return 0;
}
cs

 

3.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <math.h>
 
void quadratic(int a, int b, int c, double* xplus, double* xminus)
{
    *xminus = (-- sqrt(b * b - 4 * a * c) / (2 * a));
    *xplus = (-+ sqrt(b * b - 4 * a * c) / (2 * a));
}
 
int main(void)
{
    int a = 1, b = 4, c = 3;
    double xplus, xminus;
 
    quadratic(a, b, c, &xplus, &xminus);
 
    printf("첫번째 실근: %lf", xplus);
    printf("두번째 실근: %lf", xminus);
 
    return 0;
}
cs

 

4.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
 
void get(double value, int *i_part, double *f_part)
{
    *i_part = (int)value;
    *f_part = value - *i_part;
}
 
int main(void)
{
    int i;
    double f;
 
    get(3.14&i, &f);
 
    printf("정수부 = %d\n", i);
    printf("소수부 = %lf\n", f);
 
    return 0;
}
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