C언어 array_max() 구현

(C언어 array max()에서 넘어옴)

1 개요[ | ]

C언어 array_max() 구현
C언어 max()
int
#include <stdio.h>
#define ARRAYSIZE(A) sizeof(A)/sizeof((A)[0])
int array_max(int a[], int size) {
    int max = a[0];
    for(int i=1; i<size; i++) if(a[i]>max) max=a[i];
    return max;
}
void main() {
    int nums[] = {3, 6, 2, 8, 1};
    int size = ARRAYSIZE(nums);
    printf("%d", array_max(nums,size)); // 8
}
float
#include<stdio.h>
#define ARRAYSIZE(A) sizeof(A)/sizeof((A)[0])
float floatArray_max(float a[], int size) {
    float max = a[0];
    for(int i=1; i<size; i++) if( a[i]>max ) max=a[i];
    return max;
}
void main() {
    float nums[] = {3.2, 6.2, 2.2, 8.2, 1.2};
    int size = ARRAYSIZE(nums);
    printf("%f", floatArray_max(nums,size)); // 8.200000
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}