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

后端 未结 3 580
温柔的废话
温柔的废话 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:14

    int input;
    int max = 0;
    int min = 0;
    
    cout << "Enter number: ";
    while (input != -1)
    {
        cin >> input;
        if(input != -1)
        {
            if(input > max)
            {
                max = input;
            }
    
            if(input < min)
            {
                min = input;
            }
        }
    }
    cout <<"Max: " << max << " Min " << min << endl;
    

    }

提交回复
热议问题