The following code totals the values in two arrays: numberArray1 and numberArray2. Both arrays have 25 elements. Will the code print the correct sum of values 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 < 24; count++)
total += numberArray1[count];
cout ≪ "The total for numberArray1 is " ≪ total ≪ end1;
//Calculate and display the total of the second array.
for (count = 0; count < 24; count++)
total += numberArray2[count] ;
cout ≪ "The total for numberArray2 is "« total << end1;
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Additional Engineering Textbook Solutions
Modern Database Management (12th Edition)
Starting Out with Java: Early Objects (6th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- (Electrical eng.) Write a program that specifies three one-dimensional arrays named current, resistance, and volts. Each array should be capable of holding 10 elements. Using a for loop, input values for the current and resistance arrays. The entries in the volts array should be the product of the corresponding values in the current and resistance arrays (sovolts[i]=current[i]resistance[i]). After all the data has been entered, display the following output, with the appropriate value under each column heading: CurrentResistance Voltsarrow_forwardFill-in-the-Blank To print out all elements of a two-dimensional array you would normally use a(n) _________ loop.arrow_forwardThe 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 << end1; // Calculate and display the total of the second array.for (count = 0; count <= 25; count++) total += array2[count];cout << "The total for array2 is " << total << end1;arrow_forward
- Ch7 - Arrays java In a loop, ask the user to enter 10 integer values and store the values in an array. Pass the array to a method. In the method, use a loop to subtract 5 from each element and return the changed array to the main method.In the main method, use a loop to add the array values and display the result.arrow_forwardWhat can cause an off-by-one error when working with an array?arrow_forwardGIven the statement below: intA=(3,6,9}, A.length can't be used to display the number of elements in the array True Falsearrow_forward
- Question 1 Write a program that declares an array of 100 doubles. The program asks the user to enter a number N between 100, and then: initializes the first N elements of the array to random numbers between 1 and 100. calculates the average of these numbers and displays it. A final loop displays the elements of the array, each on a line, with an indication as to whether that number is lower or higher than the average. For example, if the numbers generated are 5, 28, 3, 8, 15, 7, 22, 6, 1, 4, then the program will print: Average = 9.9 5 28 3 8 15 7 22 6 1 4 11 11 11 -- 11 11 1- —— 11 lower than average higher than average lower than average lower than average higher than average lower than average higher than average lower than average lower than average lower than averagearrow_forwardPart 1: Randomizing an Array In this problem you will write a program that will randomize the elements of an array created by the user. 1. Prompt the user to enter an integer, then asks the user to enter that many values. Store these values in an array and print the array. Then re-shuffle the array elements so randomly. Do not just randomize the order in which they are printed; actually change the way they are stored in the array. Do not create a second array; just rearrange the elements within the array you have. (Hint: Swap elements that need to change places.) When the elements have been randomized, print the array again. 2. Create another version of your program that applies the following modification to the randomization process: elements that have been already swapped should not be swapped again. Example: if element 1 was swapped with element 10, when the 10 th element is reached it should not be swapped again. Yet if the 2 nd element is reached it can be swapped with the 10o the…arrow_forwardIf you want to use a nested for loop to process a two-dimensional array row-by-row, which dimension’s index (row or column) would you increment in the inner loop, and which would you increment in the outer loop?arrow_forward
- An array definition reserves space for the array. true or falsearrow_forwardTRUE or FALSE - A pointer can be used to access elements of an array. Select one: a.TRUE b.FALSEarrow_forwardProblem2 Write a program that display the position of a given element in an array. You should print the index (i.e. the position) of the element. If the element appears more than one time than you should print all its positions. The size of the array should be entered by the user. If the element does not occur then you should display element not found. Sample1: Enter the size of the array: 5 Enter an array of size 5: 44 5 13 44 67 Enter the element to find: 44 44 is found at position 44 is found at position 44 occurs 2 time(s) Sample2: Enter the size of the array: 4 Enter an array of size 4: 12 150 17 20 Enter the element: 18 18 is not foundarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage