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

Write a program that prompts the user to enter in an integer number representing

ID: 3767917 • Letter: W

Question

Write a program that prompts the user to enter in an integer number representing the number of elements in an integer array. Create the array and prompt the user to enter in values for each element using a for loop. When the array is full, display the following:

-The values in the array on a single line.

-The array with all of the elements reversed.

-The values from the array that have even numbered indexes. Do not use an if statement here.

-The values from the array that have odd numbered indexes. Do not use an if statement here.

-Use a separate for loop for each task.

Prompt the user one more time for a single integer. Report back whether or not the number is found in the array.

All of this work can be done in a single main( ) method.

For the remaining do each task in a separate method. A printArray method that prints any 1D array of integers. A reverse method that returns a new array with the values reverse. printOdd and printEven methods that simply print the appropriate values. A search method that returns the index of an element if it is found. See my sample output below for two separate executions of the program:

How many elements in your array?7

Enter number:5
Enter number:19
Enter number:12

Enter number:2

Enter number:0

Enter number:4

Enter number:8

Your array:

5 19 12 2 0 4 8

Your array reversed: 8 4 0 2 12 19 5

Values at even-numbered indexes: 5 12 0 8

Values at odd-numbered indexes: 19 2 4

Enter a value to look for:0

Found your value at index:4

How many elements in your array?6

Enter number:2306

Enter number:1046

Enter number:3807

Enter number:1047

Enter number:2836

Enter number:4426

Your array:

2306 1046 3807 1047 2836 4426

Your array reversed:
4426 2836 1047 3807 1046 2306

Values at even-numbered indexes: 2306 3807 2836

Values at odd-numbered indexes: 1046 1047 4426

Enter a value to look for:9

Sorry, that value was not found.

Explanation / Answer

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

void main()
{
   int n, a[100],i,s;

   cout<<"How many elements in your array?";
   cin>>n;

   for(i=0;i<n;i++)
   {
       cout<<"Enter number";
       cin>>a[i];
   }
   cout<<"Your array:";
   for(i=0;i<n;i++)
   {
       cout<<a[i]<<" ";

   }

   cout<<" Your array reversed:";
   for(i=n-1;i>=0;i--)
   {
       cout<<a[i]<<" ";

   }
   cout<<" Values at even numbered indexes:";
   for(i=0;i<n;i=i+2)
   {
       cout<<a[i]<<" ";

   }

   cout<<" Values at odd-numbered indexes:";
   for(i=1;i<n;i=i+2)
   {
       cout<<a[i]<<" ";

   }
   cout<<" Enter a value to look for:";
   cin>>s;
   for(i=0;i<n;i++)
   {
       if(a[i]==s)
       {
           cout<<"Found your value at index:"<<i;
           break;
       }
   }
   if(i==n)
   {
       cout<<"Sorry, that value was not found.";
   }
   getch();
}