"함수 max()"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 17개는 보이지 않습니다)
6번째 줄: 6번째 줄:
[[category: C]]
[[category: C]]
{{참고|C언어 array_max()}}
{{참고|C언어 array_max()}}
<source lang='c'>
<syntaxhighlight lang='c' run>
#include<stdio.h>
#include <stdio.h>
 
#define ARRAYSIZE(A) sizeof(A)/sizeof((A)[0])
int intArray_max(int arr[], int len) {
int array_max(int a[], int size) {
     int max = arr[0];
     int max = a[0];
     for(int i=1; i<len; i++) if(arr[i]>max) max=arr[i];
     for(int i=1; i<size; i++) if(a[i]>max) max=a[i];
     return max;
     return max;
}
}
void main() {
void main() {
   int nums[] = {3, 6, 2, 8, 1};
   int nums[] = {3, 6, 2, 8, 1};
   int len = sizeof(nums)/sizeof(int);
   int size = ARRAYSIZE(nums);
   printf("%d", intArray_max(nums,len));
   printf("%d", array_max(nums,size)); // 8
  // 8
}
}
</source>
</syntaxhighlight>
 
==C++==
[[분류: C++]]
{{참고|C++ array_max()}}
<syntaxhighlight lang='cpp' run>
#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
}
</syntaxhighlight>
<syntaxhighlight lang='cpp' run>
#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
}
</syntaxhighlight>
<syntaxhighlight lang='cpp' run>
#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
}
</syntaxhighlight>


==C#==
==C#==
[[분류: Csharp]]
[[분류: Csharp]]
{{참고|C샵 max()}}
{{참고|C샵 max()}}
<source lang='csharp'>
<syntaxhighlight lang='csharp' run>
using System;
using System;
using System.Linq;
using System.Linq;
36번째 줄: 73번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>
<source lang='csharp'>
<syntaxhighlight lang='csharp' run>
using System;
using System;
using System.Linq;
using System.Linq;
47번째 줄: 84번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==Excel==
==Excel==
[[category: Excel]]
[[category: Excel]]
{{참고|엑셀 MAX()}}
{{참고|엑셀 MAX()}}
<source lang='php'>
<syntaxhighlight lang='php'>
=MAX(3.14, 77.7, 5, -10.5, -4.4)
=MAX(3.14, 77.7, 5, -10.5, -4.4)
// 77.7
// 77.7
</source>
</syntaxhighlight>


==Java==
==Java==
[[분류: Java]]
[[분류: Java]]
{{참고|자바 max()}}
{{참고|자바 max()}}
<source lang='java'>
<syntaxhighlight lang='java' run>
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collections;
import java.util.Collections;
67번째 줄: 104번째 줄:
         Double[] nums = {3.14, 77.7, 5.0, -10.5, -4.4};
         Double[] nums = {3.14, 77.7, 5.0, -10.5, -4.4};
         Double max = Collections.max(Arrays.asList(nums));
         Double max = Collections.max(Arrays.asList(nums));
         System.out.println( max );
         System.out.println( max ); // 77.7
        // 77.7
     }
     }
}
}
</source>
</syntaxhighlight>
<source lang='java'>
<syntaxhighlight lang='java' run>
public class Main {
public class Main {
     public static void main(String args[]) {
     public static void main(String args[]) {
78번째 줄: 114번째 줄:
         double max = nums[0];
         double max = nums[0];
         for(double e:nums) if(max<e)max=e;
         for(double e:nums) if(max<e)max=e;
         System.out.println( max );
         System.out.println( max ); // 77.7
        // 77.7
     }
     }
}
}
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[category: JavaScript]]
[[category: JavaScript]]
{{참고|JavaScript max()}}
{{참고|JavaScript max()}}
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript' run>
console.log( Math.max(3.14, 77.7, 5, -10.5, -4.4) );
console.log( Math.max(3.14, 77.7, 5, -10.5, -4.4) );
// 77.7
// 77.7
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
{{참고|PHP max()}}
{{참고|PHP max()}}
<source lang='php'>
<syntaxhighlight lang='php' run>
echo max(3.14, 77.7, 5, -10.5, -4.4);
echo max(3.14, 77.7, 5, -10.5, -4.4); # 77.7
# 77.7
</syntaxhighlight>
</source>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
{{참고|Python max()}}
{{참고|Python max()}}
<source lang='Python'>
<syntaxhighlight lang='Python' run>
print( max(3.14, 77.7, 5, -10.5, -4.4) )
print( max(3.14, 77.7, 5, -10.5, -4.4) ) # 77.7
# 77.7
</syntaxhighlight>
</source>


==Perl==
==Perl==
[[category: Perl]]
[[category: Perl]]
<source lang='perl'>
<syntaxhighlight lang='perl' run>
use List::Util qw( max );
use List::Util qw( max );
print max(3.14, 77.7, 5, -10.5, -4.4) . "\n";
print max(3.14, 77.7, 5, -10.5, -4.4) . "\n"; # returns 77.7
# returns 77.7
</syntaxhighlight>
</source>


==SQL==
==SQL==
122번째 줄: 154번째 줄:
===MySQL/MariaDB===
===MySQL/MariaDB===
[[category:MySQL]]
[[category:MySQL]]
<source lang='MySQL'>
<syntaxhighlight lang='MySQL'>
SELECT GREATEST(3.14, 77.7, 5, -10.5, -4.4);
SELECT GREATEST(3.14, 77.7, 5, -10.5, -4.4);
# 77.7
# 77.7
</source>
</syntaxhighlight>


===Oracle===
===Oracle===
[[category: Oracle]]
[[category: Oracle]]
<source lang='sql'>
<syntaxhighlight lang='sql'>
SELECT GREATEST(3.14, 77.7, 5, -10.5, -4.4) FROM DUAL;
SELECT GREATEST(3.14, 77.7, 5, -10.5, -4.4) FROM DUAL;
-- returns 77.7
-- returns 77.7
</source>
</syntaxhighlight>
 
===SQLite===
<syntaxhighlight lang='sqlite3' run>
SELECT MAX(3.14, 77.7, 5, -10.5, -4.4);
</syntaxhighlight>


==같이 보기==
==같이 보기==

2021년 4월 13일 (화) 18:14 기준 최신판

MAX
GREATEST

1 C[ | ]

#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
}

2 C++[ | ]

#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
}
#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
}
#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
}

3 C#[ | ]

using System;
using System.Linq;
class Program {
    static void Main() {
        int[] nums = {3, 6, 2, 8, 1};
        Console.WriteLine( nums.Max() );
        // 8
    }
}
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
    }
}

4 Excel[ | ]

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

5 Java[ | ]

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
    }
}
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
    }
}

6 JavaScript[ | ]

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

7 PHP[ | ]

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

8 Python[ | ]

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

9 Perl[ | ]

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

10 SQL[ | ]

10.1 MySQL/MariaDB[ | ]

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

10.2 Oracle[ | ]

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

10.3 SQLite[ | ]

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

11 같이 보기[ | ]

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