Question: How do I do conver this code into these functions and create a new function for copy, using c++? #include 2 #include 3 #include 4
How do I do conver this code into these functions and create a new function for copy, using c++?


#include
2 #include
3 #include
4 #include
5 using namespace std;
6
7 int main()
8 {
9 const int randArraySize=20;
10 //array to store the random number
11 int RandArray[randArraySize];
12 srand(time(0));
13 //variable for loop
14 int i=0;
15 //variables to store the minimum,maximum number, and their index
16 int min=INT_MAX;
17 int max=INT_MIN;
18 int min_index=0;
19 int max_index=0;
20 int n;
21 int flag=0;
22 double avg=0;
23 //loop to store the 20 random number in the array
for(i=0;i 25 { 26 RandArray[i]=rand()%100; 27 } 28 //loop to print the array 29 for(i=0;i 30 { 31 cout 32 cout 33 } 34 //loop to find the maximum and minmum number in the array and their index 35 for(i=0;i 36 { 37 if(RandArray[i] 38 { 39 min=RandArray[i]; 40 min_index=i; 41 } 43 if(RandArray[i]>max) 44 { 45 max=RandArray[i]; 46 max_index=i; 47 } 48 } 49 //print the smallest number and its index 50 cout 51 //Print to find the largest value and its index 52 cout 53 //finding the average of largest and smallest number in the array 54 avg=(min+max)/2; 55 cout 56 cout 57 //getting input from the user 58 cout 59 cin>>n; 60 //finding the user input in the array 61 for(i=0;i { 63 if (RandArray[i]==n) 64 { 65 cout 66 flag=1; 67 } 68 } 69 if (flag==0) 70 { 71 cout 72 } 73 74 cout 75 //printing the address of every random number in the array 76 for(i=0;i 77 { 78 cout 79 } 80 cout 81 cout 82 //printing the array in the reverse order 83 for(i=randArraySize-1;i>=0;i--) 84 { 85 cout 86 } 87 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
