Write C++ statement(s) to do the following: Declare an array alpha of 50 compone
ID: 3569675 • 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-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
1) int alpha[50];
2) for(int i=0;i<50;i++)
alpha[i] = -1;
3) cout << alpha[0];
4) alpha[24] = 62;
5) alpha[9] = 3 * alpha[24] + 10;
6) for(int i=0;i<50;i++)
{
if(i%2 == 0)
cout << alpha[i];
else if(i%3 == 0)
cout << alpha[i];
else
;
}
7) cout << alpha[49];
8) for(int i=0;i<50;i++)
{
if(i%15 == 0)
cout <<" ";
cout << alpha[i];
}
9) for(int i=0;i<50;i = i+2)
alpha[i] ++;
10) int diffAlpha[50];
for(int i=1;i<50;i++)
diffAlpha[i] = alpha[i]-alpha[i-1];
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.