The following code totals the values in two integer arrays: intnumberarray1 and
ID: 640393 • Letter: T
Question
The following code totals the values in two integer arrays: intnumberarray1 and intnumberarray2. both arrays have 25 elements. will the code print correct sum of values for both arrays? Why or why not?
Dim intTotal as integer
For intCount = 0 to 24
intTotal += intNumberArray1(intCount)
Next intCount
MessageBox.Show("Total for intNumberArray1 is " & intTotal.ToString())
For intCount = 0 to 24
intTotal += intNumberArray2(intCount)
Next intCount
MessageBox.Show("Total for intNumberArray2 is " & intTotal.ToString())
Explanation / Answer
The following code totals the values in two integer arrays: intnumberarray1 and intnumberarray2. both arrays have 25 elements. will the code print correct sum of values for both arrays? Why or why not?
Dim intTotal as integer = 0;
For intCount = 0 to 24
intTotal += intNumberArray1(intCount)
Next intCount
MessageBox.Show("Total for intNumberArray1 is " & intTotal.ToString())
intTotal = 0;
For intCount = 0 to 24
intTotal += intNumberArray2(intCount)
Next intCount
MessageBox.Show("Total for intNumberArray2 is " & intTotal.ToString())
It will not print correct sum of values for both arrays are intTotal is not initialized with zero.
make first statement as follows.
Dim intTotal as integer = 0
After summing first array again reset intTotal to zero.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.