Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Arrays no Write some code to perform each of the following tasks: ra a) Define a

ID: 3714994 • Letter: A

Question

Arrays no Write some code to perform each of the following tasks: ra a) Define a constant MAx that holds a value of 25. b) Define an array of integers, num, containing MAX elements and initialize each of the the elements of the array to0, c) What is the name of the fifth element of the array? d) Output the value of the third element of the array. e) Assign a value into the fourth element of array num. f) Initialize each of the 25 elements of the array to 100. g) Sum up the elements of array num into summation variable sum h) Copy the contents of array num into array foo, also of size MAX. ) Increment each element of array foo by a value of 1. 2. The code below assigns a random number from 1 to 10,000 into each element of array num. Writre a function that receives the array as a parameter and returns the largest value of array. srandl (unsigned int) time (NULL) ) for (i = 0; i

Explanation / Answer

1)

a)
   //Define a constnat MAX=25
   const int MAX=25;

b)

   //define an array of integers,num
   int num[MAX];
   for(int index=0;index<MAX;index++)
       num[index]=0;

c.Name of fifth element

   //num[4] since elements start frmom
   //index=0

   //d.Output value of 3 rd element
   cout<<num[3];
  
e.assign value 10(some integer) in fourth element
   num[3]=10;

f.intialize each of 25 elements to 100

   for(int index=0;index<MAX;index++)
       num[index]=100;

g.summartion the values of num

   //array into sum
   for(int index=0;index<MAX;index++)
       sum=sum+num[index];

h.copy contents of num into foo array

   int foo[MAX];
   for(int index=0;index<MAX;index++)
       foo[index]=num[index];

i.increment each elemnt of foo by 1

       for(int index=0;index<MAX;index++)
       foo[index]=foo[index]+1;
--------------------------------------------------------------------------------------------------------------------

2)

/**The function that takes array and size
and find the max element in the arrya
and reutrn the max element */
int getLongestvalue(int num[] ,int MAX)
{
   //assume start element is longest
   int max=num[0];

   //update the max element
   for(int index=0;index<MAX;index++)
       if(num[index]>max)
           max=num[index];

   //return max value
   return max;
}

Note :post question 3 in another post

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote