mardi 20 décembre 2022

Generating one random number from given input [C++]

#include <iostream>
using namespace std;

int main()
{

int n;
int *array;
array= new int[n];
cout<<"Masukkan ukuran array"<< endl;
cin >> n;
cout << "Masukkan nilai array" << endl;

for (int i=0; i < n; i++)
{
    cin >> array[i];
}

cout << "hasil array adalah"<< endl;
for (int i=0; i < n; i++)
{
    cout<<array[i]<< " ";
}
cout << endl<< "hasil urut adalah"<< endl;
for(int i = 0; i < n;i++)
{
    for (int j=i+1;j<n;j++)
    {
        if (array[j]<array [i])
        {
            int temp=array[i];
            array[i]=array[j];
            array[j]= temp;
        }
        else;
    }
}

for (int i=0;i<n;i++)
{
    cout << array[i]<< " ";
}




return 0;

}

i'm trying to generate a single random number from the inputted value for example i input 1,3,6,8 to my array and im trying to figure it out how to generate a random number from given input so the output will be 3 or 6 or 8 etc




Aucun commentaire:

Enregistrer un commentaire