예제/Layer7_20160411

[C언어] 포인터 - 문제 만들기~ [정답]

Mosu(정종인) 2016. 4. 11. 16:32
반응형


-첫 번째 문제 정
답-



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 check(int input){
    if(input%8!=0){
        return 0;
    }
    else
        return 1;
}
 
int main(){
    double *arr=(double *)malloc(sizeof(double)*100000000);
    double *ptr;
    double bunmo, bunja;
    int input;
    int i;
 
    do{
        scanf("%d", &input);
    }while(check(input)!=1);
 
    ptr=arr;
    arr[0]=10.0;
    bunmo=2.0;
    bunja=5.0;
    
    for(i=1; i<=input/8++i){
        arr[i]=arr[i-1]*(bunja++/bunmo++);
    }
    printf("%.1lf", arr[input/8]);
    free(arr);
    return 0;
}
cs







-두 번째 문제 정답-



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
 
int main(){
    int arr[6]={0,};
    int input1;
    char input2;
    int i;
    int **a, **b, **c, *d, *e;
    int *temp1, *temp2, *temp3;
    temp1=&arr[5];
    temp2=&arr[5];
    temp3=&arr[5];
 
    for(i=0; i<5++i){
        scanf("%d", &input1);
        arr[i]=input1;
    }
 
    for(i=0; i<5++i){
        if(*temp1<arr[i]){
            temp1=&arr[i]; //temp1==>최댓값 : a
        }
        if((*temp2>arr[i])||i==0){
            temp2=&arr[i]; //temp2==>최솟값 : c
        }
        if(*temp3<arr[i]&&arr[i]%2==1){
            temp3=&arr[i]; //temp3==>홀수 최댓값 : b
        }
    }
 
    a=&temp1;
    b=&temp3;
    c=&temp2;
    d=&arr[0];
    e=&arr[4];
 
    for(i=0; i<5++i){
        fflush(stdin);
        scanf(" %c", &input2);
        if(input2=='a'){
            printf("%d "**a);
        }
        else if(input2=='b'){
            printf("%d "**b);
        }
        else if(input2=='c'){
            printf("%d "**c);
        }
        else if(input2=='d'){
            printf("%d "*d);
        }
        else if(input2=='e'){
            printf("%d "*e);
        }
    }
    return 0;
}
cs









-세 번째 문제 정답-



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 main(){
    char arr[100];
    char input1, input2;
    char *ptr;
    int i=0;
 
    ptr=&arr[0];
 
    fgets(arr, 100, stdin);
    scanf("%c %c", &input1, &input2);
 
    while(ptr[i]!='\0'){
        if(ptr[i]==input1){
            ptr[i]=input2;
        }
        ++i;
    }
 
    printf("%s", ptr);
}
cs


반응형