在数组中寻找最大值 [英] Finding max value in an array

查看:66
本文介绍了在数组中寻找最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int highNum = 0;
int m;
int list[4] = {10, 4, 7, 8};
    for (m = 0 ; m < size ; m++);
    {
        if (list[m] > highNum)
            highNum = list[m];
            cout << list[m];
    }
cout << highNum;

我试图找到一个简单的循环来存储数组中的最大值,我写这个想法是可行的,但是由于某种原因,在for循环开始时,它将m变量存储为4并退出了环形.有人可以帮我吗?

I am trying to find a simple loop to store a max value from an array, and I wrote this thinking it would work, but for some reason at the beginning of the for loop it stores the m variable as 4 and exits the loop. Can someone help me out?

推荐答案

for 语句后,您使用分号:

You have a semicolon after your for statement:

for (m = 0 ; m < size ; m++);
{

这应该是:

for (m = 0 ; m < size ; m++)
{

这篇关于在数组中寻找最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆