The following code totals the values in each of two arrays described in question 31. Will the code print the correct total for both arrays? Why or why not?
int total= 0; // Accumulator
int count; // Loop counter
// Calculate and display the total of the first array.
for (count = 0; count < 25; count ++)
total += array1[count];
cout << "The total for array1 is" << total << end l ;
// Calculate and display the total of t he second array.
for (count = 0; count < 25; count ++)
total += array2[count];
cout << "The total for array2 is"<< total<< end l ;
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java How To Program (Early Objects)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Concepts of Programming Languages (11th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
- Arrays Write three statements to print the first three elements of array runTimes. Follow each statement with a newline. Ex: If runTime = {800, 775, 790, 805, 808}, print:800 775 790 Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5-element array (int runTimes[5]). See "How to Use zyBooks".Also note: If the submitted code tries to access an invalid array element, such as runTime[9] for a 5-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message. #include <iostream>using namespace std; int main() {const int NUM_ELEMENTS = 5;int runTimes[NUM_ELEMENTS];int i; for (i = 0; i < NUM_ELEMENTS; ++i) {cin >> runTimes[i];} /* Your solution goes here */ return 0;} Please help me with this problem using c++.arrow_forward1. Write a for loop to initialize the following array with value 0.0 double[] balances = new double [5] 2. Write a for-each loop to print out every element of the above array.arrow_forwardWrite statements to do the following: a. Create an array to hold 10 double values. b. Assign the value 5.5 to the last element in the array. c. Display the sum of the first two elements. d. Write a loop that computes the sum of all elements in the array. e. Write a loop that finds the minimum element in the array. f. Randomly generate an index and display the element of this index in the array. g. Use an array initializer to create another array with the initial values 3.5, 5.5, 4.52, and 5.6.arrow_forward
- C++; In all different cases please create a const int SIZE_EX_1 = 10; // type of declaration. Do not hard code numbers into. #1) Fill an array of 10 elements with the digits 1 to 10. Then print the contents of the array. (Do not fill and print in one loop ) #2) Fill an array of 20 elements with the squares of the digits 1 to 20. #2B ) Then print the array contents. #2C) Then print the differences of each pair of elements. #3) Create an integer array of 40 elements #3B ) Fill the first 2 elements with 1 and 2. To be more clear, set a 1 into the very first element and set a 2 in the second element. #3C) Then for the remaining 38 elements set the sum of the previous two elements into the element. #3D) Display the values of the 40 elementsarrow_forwardin C 1- Declare and initialize all values to zero an array of integers 10 x 10 named“thor”.2- Write the code (using for loop) to fill the first row of the array with values 12 3 4 5 6 7 8 9 103- Write the code (using for loop) to fill the last column of the array withvalues 10 20 30 40 50 60 70 80 90 1004- Write the necessary code in main to output the values of thor with eachrow on a separate line and the values of each column separated by acomma.arrow_forwardc++ 1. Does the element of an array have a default value? 2. Which of the following statements are valid array declarations? double d[30]; char[30] r;arrow_forward
- Javascript programming question below Write the pseudocode for an application that will:a. Prompt a user for three numbers.b. Store the values entered by a user in an array as they are provided bythe user.c. Ask a user if they would like to search for a value:i. If the user wishes to search for a value, the user needs to beprompted for a value to search for. If the value is found, anotification needs to be provided to the user.d. Use a for loop to cycle through the arrays in order to calculate anddisplay the total of the values stored in the array.arrow_forwardPart 1 code: #include <iostream> using namespace std; #include <cstdlib> int main() { srand(17); const int ARRAYSIZE = 20; // size for the array int RandArray[ARRAYSIZE]; // array declared int i; // to iterate the loop // this loop will store thei random number in the array for (i = 0; i < ARRAYSIZE; i++) RandArray[i] = rand() % 100; // this loop will print the array for (i = 0; i < ARRAYSIZE; i++) cout <<"randArray["<< i <<"]=" << RandArray[i] << endl; return 0; } At the bottom of the code from Part 1: Write code to find the largest value (and the index where it resides. Loop through all indices and update largestFoundSoFar (and the indexOfLargest) if the value in the array is even larger. At the end, print the largestFoundsoFar, and the index. largestFoundSoFar=95 at index 16 code format: #include <iostream>using namespace std; #include <cstdlib> // required for rand() int main(){// Put Part1 code here…arrow_forwardWrite three statements to print the first three elements of array runTimes. Follow each statement with a newline. Ex: If runTimes = {800, 775, 790, 805, 808}, print:800 775 790 Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5-element array (int runTimes[5]). Also note: If the submitted code tries to access an invalid array element, such as runTime[9] for a 5-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message. #include <iostream>using namespace std; int main() { const int NUM_ELEMENTS = 5; int runTimes[NUM_ELEMENTS]; int i; for (i = 0; i < NUM_ELEMENTS; ++i) { cin >> runTimes[i]; } /* Your solution goes here */ return 0;arrow_forward
- JAVA CODE PLEASE 2. Insertion Sort Practice ll by CodeChum Admin Write a program that continuously accepts integer user input and assign the value in an array with a size of 100. The input process terminates if either of the following is true: inputted value is 0 input count is greater than 100 Sort the values inside the array in ascending order using the insertion sort algorithm. Print out the sorted values inside the pair of square brackets [ ] where the elements are separated by a comma and a space ", " Input 1. Multiple lines containing an integer Output Enter·number·1:·1 Enter·number·2:·2 Enter·number·3:·3 Enter·number·4:·4 Enter·number·5:·5 Enter·number·6:·0 [1,·2,·3,·4,·5]arrow_forwardIdentify error(s), if any, in the following array declarations. If a statement is incorrect, provide the correct statement. a. int primeNum[99];b. int testScores[0];c. string names[60];d. int list100[0..99];e. double[50] gpa;f. const double LENGTH = 26;double list[LENGTH - 1];g. const long SIZE = 100;int list[2 * SIZE];arrow_forwardіmрlеmеոt thе fоllоwіոg ехрrеssіоո іո аssеmbly lаոguаgе: Create a DWORD array named ‘z’ of size 3 using DUP operator. Leave the array ‘z’ uninitialized. You can denote the items in the array as [ z0, z1, z2]z0, z1, z2] , where z0z0 is the first item, z1 z1 is the second item, z2z2 is the third item Update each array item using the following expressions. z0=x+130z0=x+130 z1=y−x+ z0z1=y−x+ z0 z2=r+x−z1z2=r+x−z1 Where x, y, r are 16-bit integer memory variables. x = 10, y = 15, r = 4 Use mov, movzx, movsx, add, sub instructions only. (hint: Do not alter the value of x, y and r during the computation. Transfer them to appropriate registers to do computation) At the end, open memory window to see the variable z stored in memory (little endian format). Use the debugger to verify your answer.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning