Write C++ statement(s) to do the following: (1, 2) a. Declare an array alpha of
ID: 3816953 • Letter: W
Question
Write C++ statement(s) to do the following: (1, 2) a. Declare an array alpha of 50 components of type int. b. Initialize each component of alpha to -1. c. Output the value of the first component of the array alpha. d. Set the value of the twenty-fifth component of the array alpha to 62. e. Set the value of the tenth component of alpha to three times the value of the fiftieth component of alpha plus 10. f. Use a for loop to output the value of a component of alpha if its index is a multiple of 2 or 3. g. Output the value of the last component of alpha. h. Output the value of the alpha so that 15 components per line are printed. i. Use a for loop to increment every other element (the even indexed elements). j. Use a for loop to create a new array, diffAlpha, whose elements are the differences between consecutive elements in alpha.Explanation / Answer
a) int alpha[50];
b) for(int i=0; i<50; i++){
alpha[i] = -1;
}
c) cout << alpha[0];
d) alpha[24]= 62;
e) alpha[9] = 3* alpha[14] + 10;
f) for(int i=0; i<50; i++) {
if(i%2==0 || i%3 == 0){
cout << alpha[i];
}
}
g) cout << alpha[49];
h) for(int i=0; i<50;i+15;){
cout<< alpha[i] << alpha[i+1] << alpha[i+2] << alpha[i+3] << alpha[i+4] << alpha[i+5] << alpha[i+6] << alpha[i+7] << alpha[i+8] << alpha[i+9] << alpha[i+10] << alpha[i+11] << alpha[i+12] << alpha[i+13] << alpha[i+14] << endl;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.