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

USING C++ Write the code to: 1. Declare an integer array named stuff with 20 ele

ID: 3698146 • Letter: U

Question

USING C++

Write the code to:

1.                 Declare an integer array named stuff with 20 elements

2.                 Initialize each element of the array stuff to to value 100.

3.                 Ask the user to enter each value of the array stuff (prompt and input)

4.                 Print all elements of the stuff array

5.                 Print all elements of the array stuff in reverse order

6.                 Sum all elements of the array stuff

7.                 Determine the average of all elements in the array stuff

8.                 Find the largest element in the array stuff

9.                 Subtract 1 from every element of the stuff array.

10.             Divide all even-numbered elements in the stuff array (stuff[2],stuff[4],..stuff[20]) by 5, i.e. stuff[2] = stuff[2]/5;...

Explanation / Answer

#include<iostream.h>
#include<conio.h>

void main()
{
   int stuff[20],i,s=0,max;
   double av;

   for(i=0;i<20;i++)
   {
       stuff[i]=100;
   }

   for(i=0;i<20;i++)
   {
       cout<<"Enter no";
       cin>>stuff[i];
   }

   cout<<"array contents are:"<endl;
   for(i=0;i<20;i++)
   {
       cout<<stuff[i]<<endl;
   }
   getch();
   cout<<"array contents reverse order are:"<endl;
   for(i=20;i>=0;i--)
   {
       cout<<stuff[i]<<endl;
   }
   getch();

   for(i=0;i<20;i++)
   {
       s=s+stuff[i];
   }

   av=s/20;
   cout<<"Average is ="<<av<<endl;

   max=stuff[0];
   for(i=0;i<20;i++)
   {
       if(stuff[i]>max)
           max=stuff[i];

   }
  
   cout<<"Largest element os array is "<<max<<endl;

   for(i=0;i<20;i++)
   {
       stuff[i]=stuff[i]-1;
   }

   cout<<"array contents are:"<endl;
   for(i=0;i<20;i++)
   {
       cout<<stuff[i]<<endl;
   }
   getch();

   for(i=0;i<20;i++)
   {
       if(i%2==0)
           stuff[i]=stuff[i]/5;

   }
  
   cout<<"array contents are:"<endl;
   for(i=0;i<20;i++)
   {
       cout<<stuff[i]<<endl;
   }
   getch();
}