0
点赞
收藏
分享

微信扫一扫

五只小猪的案例(五只小猪 比较体重的大小)

#include<iostream>

using namespace std;

int main() {

int arr[5]= { 100,200,300,400,50 };

int max = 0;//先认定最大值是下标为0 的100

 for(int i = 0; i < 5; i++) {

  if (arr[i] > max) {

   //如果更新的元素大于我认定的最大值,就更新最大值

   max = arr[i];    

  }

 }

 cout << "小猪的最大体重为:" << max << endl;//要放到最外面 ,因为在for循环里会把每次赋值的数打印出来

   

system("pause");

return 0;


}

举报

相关推荐

0 条评论