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

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

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

 

본문. 거듭 제곱 함수 power()함수 만들기

 

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
#include <stdio.h>
 
double power(int x, int y) {
    int i;
    double sum = 1;
 
    for (i = 0; i < y; i++) {
        sum = sum * x;
    }
 
    return sum;
}
 
int main(void) {
    
    int fir, sec;
    double result;
 
    printf("제곱할 수를 입력하시오(x, y)");
    scanf("%d %d"&fir, &sec);
 
    result = power(fir, sec);
 
    printf("값: %lf", result);
 
    return 0;
}
cs

 

2.

 

소스파일 add.c

1
2
3
4
5
6
int add(int x, int y) {
 
    int sum = x + y;
 
    return sum;
}
cs

 

소스파일 main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
 
int main(void) {
    
    int first, second;
 
    printf("정수를 입력하시오: ");
    scanf("%d"&first);
    printf("정수를 입력하시오: ");
    scanf("%d"&second);
 
    printf("합계 = %d", add(first, second));
 
    return 0;
}
cs

 

3.

 

소스파일 hello.c

1
2
3
4
5
6
7
8
#include <stdio.h>
 
void hello(char* name) {
 
    printf("안녕 %s", name);
 
}
 
cs

 

소스파일 main.c

1
2
3
4
5
6
7
8
9
#include <stdio.h>
#include "hello.h"
 
int main(void) {
 
    hello("철수");
 
    return 0;
}
cs

 

헤더파일 hello.h

1
2
3
#pragma once
 
void hello(char* name);
cs

 

4.

소스파일 array.c

 

 

 

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>
#include "array.h"
 
int get_sum_of_array(int a[], int size) {
    int i, sum = 0;
 
    for (i = 0; i < size; i++)
    {
        sum += a[i];
    }
 
    return sum;
}
 
void print_array(int a[], int size) {
    int i;
 
    printf("[ ");
 
    for (i = 0; i < size; i++)
    {
        printf("%d ", a[i]);
    }
 
    printf("]\n");
}
cs

 

소스파일 main.c

1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>
#include "array.h"
 
int main(void) {
    int num[10= { 12345678910 };
 
    print_array(num, 10);
 
    printf("배열 요소들의 합 = %d", get_sum_of_array(num, 10));
 
    return 0;
}
cs

 

헤더파일 array.h

1
2
3
4
5
6
#pragma once
 
int get_sum_of_array(int a[], int size);
 
void print_array(int a[], int size);
 
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