Fill this for me please. #include <iostream> #include <iomanip> using namespace
ID: 3730947 • Letter: F
Question
Fill this for me please.
#include <iostream>
#include <iomanip>
using namespace std;
// You can use magic numbers on the quiz.
int main()
{
// DO_02: Declare an array myArray of type float of 50 elements.
// DO_03: Input a number into the first element of myArray.
// DO_04: Input a number into the last element of myArray.
// DO_05: Complete the following statements to display
// the first and the last element of myArray. End each
// statement with an endl.
cout << "The first array element is "
cout << "The last array element is "
cout << endl;
// DO_06: Assign the sum of the two elements above to the
// second element of myArray.
// DO_07: Complete the following statements to display
// the second element of myArray.
cout << "The second array element is "
cout << endl;
// DO_08: Use a for loop to input values to the first 30 elements
// of myArray, overwriting the values read earlier.
// DO_9 Double the second array element of myArray and overwrite the
// previous value.
// DO_10: Subtract 1 from the first array element of myArray and
// overwrite the previous value.
// DO_11: Use a for loop to compute the largest value of the first
// 15 elements of myArray and store the result in max.
float max;
cout << "The largest value of the first 15 elements is "
<< max << '.' << endl;;
return 0;
}
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
// You can use magic numbers on the quiz.
int main()
{
// DO_02: Declare an array myArray of type float of 50 elements.
float myArray[50];
// DO_03: Input a number into the first element of myArray.
printf("Enter a number into for first element of myArray");
scanf("%f",&myArray[0]);
// DO_04: Input a number into the last element of myArray.
printf("Enter a number for last element of myArray");
scanf("%f",&myArray[49]);
// DO_05: Complete the following statements to display
// the first and the last element of myArray. End each
// statement with an endl.
cout << "The first array element is " <<myArray[0]<<endl;
cout << "The last array element is " <<myArray[49];
cout << endl;
// DO_06: Assign the sum of the two elements above to the
// second element of myArray.
myArray[1]=myArray[0]+myArray[49];
// DO_07: Complete the following statements to display
// the second element of myArray.
cout << "The second array element is "<<myArray[1];
cout << endl;
// DO_08: Use a for loop to input values to the first 30 elements
// of myArray, overwriting the values read earlier.
for(int i=0;i<30;i++){
printf("Enter element %d",i);
scanf("%f",&myArray[i]);
}
// DO_9 Double the second array element of myArray and overwrite the
// previous value.
myArray[1]=myArray[1]*2;
// DO_10: Subtract 1 from the first array element of myArray and
// overwrite the previous value.
myArray[0]=myArray[0]-1;
// DO_11: Use a for loop to compute the largest value of the first
// 15 elements of myArray and store the result in max.
float max;
max=myArray[0];
for(int i=1;i<16;i++){
if(myArray[i]>max){
max=myArray[i];
}
}
cout << "The largest value of the first 15 elements is "
<< max << '.' << endl;;
return 0;
}
Things to know before you go to answer program.
#include <iostream>
#include <iomanip>
using namespace std;
// You can use magic numbers on the quiz.
int main()
{
// DO_02: Declare an array myArray of type float of 50 elements.
float myArray[50];
// DO_03: Input a number into the first element of myArray.
printf("Enter a number into for first element of myArray");
scanf("%f",&myArray[0]);
// DO_04: Input a number into the last element of myArray.
printf("Enter a number for last element of myArray");
scanf("%f",&myArray[49]);
// DO_05: Complete the following statements to display
// the first and the last element of myArray. End each
// statement with an endl.
cout << "The first array element is " <<myArray[0]<<endl;
cout << "The last array element is " <<myArray[49];
cout << endl;
// DO_06: Assign the sum of the two elements above to the
// second element of myArray.
myArray[1]=myArray[0]+myArray[49];
// DO_07: Complete the following statements to display
// the second element of myArray.
cout << "The second array element is "<<myArray[1];
cout << endl;
// DO_08: Use a for loop to input values to the first 30 elements
// of myArray, overwriting the values read earlier.
for(int i=0;i<30;i++){
printf("Enter element %d",i);
scanf("%f",&myArray[i]);
}
// DO_9 Double the second array element of myArray and overwrite the
// previous value.
myArray[1]=myArray[1]*2;
// DO_10: Subtract 1 from the first array element of myArray and
// overwrite the previous value.
myArray[0]=myArray[0]-1;
// DO_11: Use a for loop to compute the largest value of the first
// 15 elements of myArray and store the result in max.
float max;
max=myArray[0];
for(int i=1;i<16;i++){
if(myArray[i]>max){
max=myArray[i];
}
}
cout << "The largest value of the first 15 elements is "
<< max << '.' << endl;;
return 0;
}
Enter a number into for first element of myArray 5 Enter a number for last element of myArray 25 The first array element is 5 The last array element is 25 The second array element is 30 Enter element 0 99 Enter element 1 98 Enter element 2 97 Enter element 3 96 Enter element 4 95 Enter element 5 94 Enter element 6 93 Enter element 7 92 Enter element 8 91 Enter element 9 90 Enter element 10 9 Enter element 11 8 Enter element 12 76 Enter element 13 5 Enter element 14 4 Enter element 15 3 Enter element 16 21 Enter element 17 11 Enter element 18 12 Enter element 19 13 Enter element 20 14 Enter element 21 15 Enter element 22 16 Enter element 23 17 Enter element 24 187 Enter element 25 19 Enter element 26 10 Enter element 27 11 Enter element 28 111 Enter element 29 23 The largest value of the first 15 elements is 196.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.