W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
#include
using namespace std; int main() { // 存储不同年龄的数组 int ages[8] = {20, 22, 18, 35, 48, 26, 87, 70}; int i; // 获取数组长度 int length = sizeof(ages) / sizeof(ages[0]); // 创建一个变量并将 ages 数组的第一个元素赋值给它 int lowestAge = ages[0]; // 遍历 ages 数组元素以找出最小年龄 for (int age : ages) { if (lowestAge > age) { lowestAge = age; } } // 输出最小年龄 cout << "最小年龄是: " << lowestAge << "\n"; return 0; }