Finding Maximum and Minimum values in c++ by user input

后端 未结 3 593
温柔的废话
温柔的废话 2020-12-20 07:21

i want to know how can i find the maximum and minimum value in c++ by user input value and and user also put the limit for for loop , for example :

Write a c++ prog

3条回答
  •  渐次进展
    2020-12-20 08:12

    you should define the maximum as the lowest possible value:

    int maximum = -INFINITY;
    

    then at each value compare and set new maximum if necessary:

    if (ivalue > maximum)
        maxumum = ivalue;
    

    for minimum you would use the same kind of logic...

提交回复
热议问题