함수 max()

(함수 array max()에서 넘어옴)
MAX
GREATEST

1 C[ | ]

C
Copy
#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
}
Loading

2 C++[ | ]

C++
Copy
#include <iostream>
#include <algorithm>
#define ARRAYSIZE(A) sizeof(A)/sizeof((A)[0])
int main() {
	int nums[] = {3, 6, 2, 8, 1};
	int max = *std::max_element(nums,nums+ARRAYSIZE(nums)-1);
	std::cout << max; // 8
}
Loading
C++
Copy
#include <iostream>
#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;
}
int main() {
    int nums[] = {3, 6, 2, 8, 1};
    int size = ARRAYSIZE(nums);
    int max = array_max(nums, size);
    std::cout << max; // 8
}
Loading
C++
Copy
#include <iostream>
#include <array>
#include <algorithm>
int main() {
    std::array<int,5> arr = {3, 6, 2, 8, 1};
    int max = *std::max_element(arr.begin(),arr.end());
    std::cout << max; // 8
}
Loading

3 C#[ | ]

C#
Copy
using System;
using System.Linq;
class Program {
    static void Main() {
        int[] nums = {3, 6, 2, 8, 1};
        Console.WriteLine( nums.Max() );
        // 8
    }
}
Loading
C#
Copy
using System;
using System.Linq;
class Program {
    static void Main() {
        double[] nums = {3.14, 77.7, 5, -10.5, -4.4};
        Console.WriteLine( nums.Max() );
        // 77.7
    }
}
Loading

4 Excel[ | ]

PHP
Copy
=MAX(3.14, 77.7, 5, -10.5, -4.4)
// 77.7

5 Java[ | ]

Java
Copy
import java.util.Arrays;
import java.util.Collections;
public class Main {
    public static void main(String args[]) {
        Double[] nums = {3.14, 77.7, 5.0, -10.5, -4.4};
        Double max = Collections.max(Arrays.asList(nums));
        System.out.println( max ); // 77.7
    }
}
Loading
Java
Copy
public class Main {
    public static void main(String args[]) {
        double[] nums = {3.14, 77.7, 5.0, -10.5, -4.4};
        double max = nums[0];
        for(double e:nums) if(max<e)max=e;
        System.out.println( max ); // 77.7
    }
}
Loading

6 JavaScript[ | ]

JavaScript
Copy
console.log( Math.max(3.14, 77.7, 5, -10.5, -4.4) );
// 77.7
77.7 

7 PHP[ | ]

PHP
Copy
echo max(3.14, 77.7, 5, -10.5, -4.4); # 77.7
Loading

8 Python[ | ]

Python
Copy
print( max(3.14, 77.7, 5, -10.5, -4.4) ) # 77.7
Loading

9 Perl[ | ]

Perl
Copy
use List::Util qw( max );
print max(3.14, 77.7, 5, -10.5, -4.4) . "\n"; # returns 77.7
Loading

10 SQL[ | ]

10.1 MySQL/MariaDB[ | ]

MySQL
Copy
SELECT GREATEST(3.14, 77.7, 5, -10.5, -4.4);
# 77.7

10.2 Oracle[ | ]

sql
Copy
SELECT GREATEST(3.14, 77.7, 5, -10.5, -4.4) FROM DUAL;
-- returns 77.7

10.3 SQLite[ | ]

SQLite
Copy
SELECT MAX(3.14, 77.7, 5, -10.5, -4.4);
Loading

11 같이 보기[ | ]