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 (9th 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_forwardThe index type of an array can be any data type. True or false?arrow_forwardFill-in-the-Blank To print out all elements of a two-dimensional array you would normally use a(n) _________ loop.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_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_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_forwardFYI: Please write the code in Pseudocode (no programming language please) 1. Write a pseudocode that outputs the contents of parallel arrays. You do NOT have to write the entire program. The first array will hold phone numbers The second array will hold company names You do NOT need to load the arrays. Your code can assume they are already loaded with data. arrays are named phone[] and company[]arrow_forward
- If 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_forwardAn 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_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