需要帮助找到一组数字的数量最多和最小数量

Need help finding the largest number and the smallest number of a group of numbers

本文关键字:数字 小数 一组 帮助      更新时间:2023-10-16

正如标题所示,我需要帮助找到一组数字中的最大数字和最小数字,然后在最后显示。每次都会随机生成一组数字。如果有人能够解释如何制作它,也将非常感谢它,以显示所选的随机数,而不是总数,同时仍在计算总数(平均)。谢谢:)

P.S抱歉,如果凹痕很奇怪,这是我在这里的第一篇文章。

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
    int Total = 0; // total of all numbers
    int AOT; //amount of times
    int i;
    cout << "How many random numbers should this machine make?" << endl;
    cin >> AOT;
    cout << endl;
    srand(time(0));
    for(i=1;i<=AOT;i++)
    {
        //makes a random number and sets it to the total
        Total = Total + (rand()%10);
        //just some fancy text
        cout << "The total after " << i << " random number/s is ";
        cout << Total << endl;
    }
    cout << endl;
    cout << endl;
    // ALL THE DATA ON THOSE NUMBERS
    cout << "The amount of numbers there were is " << AOT << endl;
    cout << "The average for the random numbers is " << Total / AOT << endl;
}

在生成随机数时分配它们并打印临时号码以向用户显示数字组。初始化到变量,存储该组的最小数量和最大数量,到该临时数字。

将其生成数字随机数进行比较,以查找其小于"最小"或大于"最大"的数字,并相应地将它们分配给变量。

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
    int smallest, largest, temp;
    int AOT; //amount of times
    int i;
    cout << "How many random numbers should this machine make?" << endl;
    cin >> AOT;
    cout << endl;
    srand(time(0));
    cout<<" Random Numbers are:";
    smallest = rand()%10;
    cout<<smallest<<'t';
    largest = smallest;
    for(i=1;i<AOT;i++)
    {
        temp = (rand()%10);
        cout<<temp<<'t';
        if(temp < smallest)
        {
            smallest =  temp;
        }
        else if(temp > largest)
        {
            largest = temp;
        }
    }
    cout << endl;
    cout << endl;
    // ALL THE DATA ON THOSE NUMBERS
    cout << "The smalles number is " << smallest << endl;
    cout << "The largest number is " << largest << endl;
}