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

Write C++ statement(s) to do the following: Declare an array alpha of 50 compone

ID: 3717285 • Letter: W

Question

Write C++ statement(s) to do the following: Declare an array alpha of 50 components of type int. Initialize each component of alpha to -1. Output the value of the first component of the array alpha. Set the value of the twenty-fifth component of the array alpha to 62. Set the value of the tenth component of alpha to three times the value of the fiftieth component of alpha plus 10. Use a for loop to output the value of a component of alpha if its index is a multiple of 2 or 3. Output the value of the last component of alpha. Output the value of the alpha so that 15 components per line are printed. Use a for loop to increment every other element (the even indexed elements). Use a for loop to create a new array, diffAlpha, whose elements are the differences between consecutive elements in alpha.

Explanation / Answer

#include<iostream>
using namespace std;
int main()
{
int alpha[50];//declaring an array named alpha of size 50
for(int i=0;i<50;i++)
{
alpha[i]=-1;//initializing each component of alpha to -1
}
cout<<"the first component of the array alpha"<<endl;
cout<<alpha[0]<<endl;//output the first component of the array alpha

alpha[24]=62;/* setting the value of the 25th element to be 62 . since the index
starts from 0 we consider the 24th element be the 25th element*/

alpha[9]=(3*alpha[15])+10;
/*setting the value off the 10th element */


cout<<"the components of the array alpha"<<endl;
for(int i=0;i<50;i++)/* using the for loop to display the contennt
of the alpha components only when its index is divisible be either by 3 or 2 */

{
if(i%2==0 || i%3==0)
{
cout<<alpha[i]<<" ";
//displaying the components of the array alpha
  
}
}
cout<<endl;
  
cout<<"the last component of the array alpha"<<endl;
cout<<alpha[49]<<endl;
  
/*output the value of the last component of the array alpha since the index
starts from 0 the last component can be considered as 49 */
cout<<"the components of the alpha after incrementing:"<<endl;
for(int i=0;i<49-1;i++)
{
if(i%2==0)
{
alpha[i]++;
cout<<alpha[i]<<" ";
}
}
cout<<endl;
int diffarray[50];/*creating the another array that stores the
difference of the consecutive elements(component) in the alpha
array */
for(int i=0;i<49;i++)
{
diffarray[i]=alpha[i]-alpha[i+1];//performing the operation
}
cout<<"the components of diff array is:"<<endl;
for(int i=0;i<50;i++)
{
cout<<diffarray[i]<<" ";//output the diffarray
}
  
return 0;
}

output:

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