I'm trying to generate 100 random numbers from 1-100 into an array. I can generate the 100 random numbers but don't know how to put it into an array.

#include<iostream>
using namespace std;


int main()
{
int ar;


for(int i=0; i<100; i++)
{
ar =(rand()%100);
cout<<ar<<" ";
}


}

first declare an array of integers int ar[100]; second use it inside the loop

for(int i=0; i<100; i++)
{
        ar[i] =(rand()%100);
        cout<<ar[i]<<" ";
}

> int ar[100];
But if you write the code on this day, it would be int arrrrrr[100];

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.