c++ please help Create two arrays of 20 elements, called myArray1 and myArray2
Create a function randBetween that returns an integer between 2 integer inputs (int randBetween(int min, int max));
Fill the myArray1 with the random values.
Loop thru the myArray1 and find the difference between the element i and element i + 1; put that difference in array2
example:
array1 = {1, 3, 4, 5}
array2 ends up having {-2, -1, -1}
Loop thru myArray1 and find the min and the max of the myArray1.
Loop thru myArray2 and find the min and the max of myArray2.
print myArray1, then print its min and max.
print myArray2, then print its min and max.
ANSWER: Here I am giving you the code and output please like it.
CODE:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int randBetween(int min , int max){ // it is the function to
generate a random number
return rand()%(max-min + 1) + min;
}
int main() {
int myArray1[20];// declared both array here
int myArray2[20];
int min=1;
int max=100;
for(int i=0;i<20;i++){
myArray1[i]=randBetween(min,max);
}
for(int i=0;i<20;i++){
myArray2[i]=myArray1[i]-myArray1[i+1];
}
int minMyarray1=myArray1[0];
int maxMyarray1=myArray1[0];
for(int j=0;j<20;j++){// Finding the min and max of the first
array
if(myArray1[j]<minMyarray1)
minMyarray1=myArray1[j];
if(myArray1[j]>maxMyarray1)
maxMyarray1=myArray1[j];
}
int minMyarray2=myArray2[0];
int maxMyarray2=myArray2[0];
for(int j=0;j<19;j++){ // Finding the min max of the second
array and it will be the 19 elements array.
if(myArray2[j]<minMyarray2)
minMyarray2=myArray2[j];
if(myArray2[j]>maxMyarray2)
maxMyarray2=myArray2[j];
}
cout<<"myArray1:";
for(int i=0;i<20;i++)
cout<<myArray1[i]<<" ";
cout<<"\nMin and Max:"<<minMyarray1<<"
"<<maxMyarray1;
cout<<"\nmyArray2:";
for(int i=0;i<19;i++)
cout<<myArray2[i]<<" ";
cout<<"\nMin and Max:"<<minMyarray2<<"
"<<maxMyarray2;
return 0;
}
OUTPUT:

c++ please help Create two arrays of 20 elements, called myArray1 and myArray2 Create a function...
C++ File I/O Create a program that will work for all "infile.txt" of similar structure: The first line will contain two integers. The first integer is the number of elements in array1, and the second integer the number of elements in array2. The second line will contain all the values of array1, and the third line will contain all values of array2. All numbers are separated by a space and all lines separated by a newline character. "infile.txt" has three...
Need help with java code, this is all in a method 1) 3 different arrays are brought in 2) I create local array called arrayWithLargestValues which is the size of the largest array from the 3 brought in 3) I need to somehow fill the local 'arrayWithLargestValues' with the all different largest values from the 3 different arrays hopefully I made sense sample input/output int [ ] arrayWithLargestValues = new int [ ] // this has to be set to...
c++, need help thank you
Given an array of ints, return the sum of all elements from the array that come before the first element that equals number 4 in the array. The array will contain at least one 4. Function prototype: int pre4int array ( ], int size); Hint: to find the array size, use: int size = sizeof(array) / sizeof( array[0]); Sample runs: int array1[ ] = {1, 2, 4, 1); pre4(array1, 4); // returns 3 int array2...
Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...
Programming in java
In this part of this Lab exercise, you will need to create a new class named ArrayShiftMult. This class carries out simple manipulation of an array. Then you should add a main method to this class to check that your code does what it is supposed to do. 1. Create a BlueJ project named LAB06 as follows: a. Open the P drive and create a folder named Blue), if it does not exist already. Under this folder,...
Teacher Instructions: Create the binarySearch() method for String arrays from the downloaded version for ints so the program can find String. Wrap a main around it, of course, so that we can see how it works. Provided Code: // Returns the index of an occurrence of target in a, // or a negative number if the target is not found. // Precondition: elements of a are in sorted order public static int binarySearch(int[] a, int target) { int min =...
i need help writing these programs in c++ format
1. Enter two integer arrays: array1-129, 0, -56, 4, -7 and array2-19, 12, -36, -2, 12 3. Write the code to form and display another array array3 in which each element is the sum of numbers in the position in both arrays. Use pointers and functions: get array0. process arrays0 and show array0 (50 points) 2. Enter a positive 5-digit integer via the keyboard. Display each digit and fol- lowed by...
Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...
c++ please help You are going to create a PowerBall Lottery game with functions. First, you are going to generate 5 UNIQUE numbers between 1 and 69. Then you are going to generate the powerball number, which is a number between 1 and 26. Next you are going to ask the user for 5 numbers. Users should only be allowed to enter numbers in the range 1-69 for regular numbers, 1-26 for powerball pick. You will compare each of the...
using matlab
In Class Exercises 8-Arrays For the following exercises, assume an array is already populated, your job is to write a program that traverses the array. DO NOT HARD CODE the last index. In other words, you code for 1-4&6 should be able to handle the following 2 arrays: amp2 10 array1 [52, 63, 99, 71, 3.1] array2 - [99:-3: 45); For 5: wordArray1 wordArray2 ('number, 'arrays', 'indices', 'hello', finish' [number, 'different, 'finish? 1. Determine the sum of all...