求整数最大值的代码示例如下:
Python 示例
```python
def find_max(nums):
max_num = float('-inf') 假设最大值为负无穷大
for num in nums:
if num > max_num:
max_num = num
return max_num
nums = [1, 3, 5, 2, 4]
max_value = find_max(nums)
print("最大值为:", max_value)
```
C++ 示例
```cpp
include include int find_max(int arr[], int size) { int max_val = arr; for (int i = 1; i < size; i++) { if (arr[i] > max_val) { max_val = arr[i]; } } return max_val; } int main() { int nums[] = {1, 3, 5, 2, 4}; int size = sizeof(nums) / sizeof(nums); int max_value = find_max(nums, size); std::cout << "最大值为: " << max_value << std::endl; return 0; } ``` ```java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入三个正整数:"); int a = scanner.nextInt(); int b = scanner.nextInt(); int c = scanner.nextInt(); int max = Math.max(a, Math.max(b, c)); System.out.println("最大值为: " + max); } } ``` ```csharp using System; class Program { static void Main() { Console.Write("请输入三个正整数:"); int a = Convert.ToInt32(Console.ReadLine()); int b = Convert.ToInt32(Console.ReadLine()); int c = Convert.ToInt32(Console.ReadLine()); int max = Math.Max(a, Math.Max(b, c)); Console.WriteLine("最大值为: " + max); } } ``` 这些示例展示了如何在不同编程语言中求一组整数中的最大值。你可以根据自己的需求和使用的编程语言选择合适的示例。Java 示例
C 示例