Question

In: Computer Science

c++ I need a code that will fill an array size of 1000, an array of...

c++

I need a code that will fill an array size of 1000, an array of size 2000, and an array size of 10000, with random int values.

Basically like this:

array1[1000] = filled all with random numbers

array2[2000] = filled all with random numbers

array3[10000] = filled all with random numbers

C++

no need for print

Solutions

Expert Solution

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main(){
   int array1[1000];
   int array2[2000];
   int array3[10000];
   int i;
   srand((unsigned) time(0)); // every time new random numbers are generated.
  
   for(i=0;i<1000;i++) // array1 filled all with random numbers
       array1[i] = rand();
      
   for(i=0;i<2000;i++) // array2 filled all with random numbers
       array2[i] = rand();
          
   for(i=0;i<10000;i++) // array3 filled all with random numbers
       array3[i] = rand();
  
   return 0;
}


Screenshot of the program

NOTE: If you want to change something , please let me know through comments; I will surely revert back to you.

Please give a up vote .....
Thank you...


Related Solutions

I need the code for a C++ program that creates an array of 5000 String objects...
I need the code for a C++ program that creates an array of 5000 String objects that will store each word from a text file. The program will read in each word from a file, and store the first 5000 words in the array. The text file should be read in from the command line.
this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
How do I write a C# and a C++ code for creating a character array containing...
How do I write a C# and a C++ code for creating a character array containing the characters 'p', 'i', 'n','e','P','I','N','E' only and then using these lower and capital case letter character generate all possible combinations like PInE or PinE or PIne or PINE or piNE etc. and only in this order so if this order is created eg. NeIP or EnPi or NeIP or IPnE and on. You can generate all the combinations randomly by creating the word pine...
language is c++ I need to take a num and put it into an array one...
language is c++ I need to take a num and put it into an array one number at a time suck that the hundredths place is at 10^3, tens is 10^2 and so on For milestone 1 you need to build a constructor that converts a int to a bigInt You need to peel off each digit from the int and place it into the appropriate location in the array of int. To do this you need to use integer...
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c...
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c program, you should end up with a simple English-French and French-English dictionary with a couple of about 350 words(I've provided 5 of each don't worry about this part). I just need a way to look up a word in a sorted array. You simply need to find a way to identify at which index i a certain word appears in an array of words...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++)...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++) sum = sum + I; printf(“sum=%d”, sum); 2) int i, v[10]; int min, k; for(i=0; i < 10; i++) scanf(“%d”, &v[i]); min = v[0] for(i=1; I < 10; i++) if(min > v[i]){ min = v[i] k = I; } printf(“%d=>%d”, k, min);
Question 2. The following code defines an array size that sums elements of the defined array...
Question 2. The following code defines an array size that sums elements of the defined array through the loop. Analyze the following code, and demonstrate the type of error if found? What we can do to make this code function correctly? #include <stdio.h> #define A 10 int main(int argc, char** argv) { int Total = 0; int numbers[A]; for (int i=0; i < A; i++) numbers[i] = i+1; int i =0; while (i<=A){    Total += numbers[i];    i++; }...
Explain this code: The structure used is max heap using array. C++ (i is the index...
Explain this code: The structure used is max heap using array. C++ (i is the index of the element to be deleted) void del(int i) {    int left,right,temp;    arr[i]=arr[n-1];    n=n-1;    left=2*i+1; /*left child of i*/    right=2*i+2; /* right child of i*/    while(right < n)    {        if( arr[i]>=arr[left] && arr[i]>=arr[right] )            return;        if( arr[right]<=arr[left] )        {            temp=arr[i];            arr[i]=arr[left];   ...
I am running this code using C to count the words in char array, but somehow...
I am running this code using C to count the words in char array, but somehow it keeps counting the total characters + 1. Any solution to fix this problem? #include <stdio.h> int main() {    char input[1001];    int count =0;    fgets(input, 1001, stdin);    char *array = input;    while(*array != '\0')       {        if(*array == ' '){            array++;        }        else{        count++;        array++;...
In C++ Write a function that took in SIZE and array [size] and counted the number...
In C++ Write a function that took in SIZE and array [size] and counted the number of elements >100
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT