Question

e TOnSWing array: intl] a- 1,3,5,7,9,11 (2x2 marks) What is the value stored in the variable total when the followings loops complete? Assume there are ho errors in the code. Assume the loops are independent (L.e., part b is not affected by part a). a) int total-0 f total-total + alil: b) int total = 0; for (inti-l; i<5; i+-2) total total + afi]i
0 0
Add a comment Improve this question Transcribed image text
Answer #1
a)
total stores value of a[0] + a[1] + a[2] + a[3] + a[4] + a[5] = 1 + 3 + 5 + 7 + 9 + 11 = 36
so, total stores a value of 36.

b)
total stores value of a[1] + a[3] = 3 + 7 = 10
so, total stores a value of 10.

Add a comment
Know the answer?
Add Answer to:
e TOnSWing array: intl] a- 1,3,5,7,9,11 (2x2 marks) What is the value stored in the variable...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array...

    Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...

  • a) (C language) Let’s consider an integer array of size 10. (10 marks, each part is...

    a) (C language) Let’s consider an integer array of size 10. (10 marks, each part is 2 marks) int a[10]; I. How would you assign a pointer, called pA, to store the address of element 0 of this array? Write the C code for your answer. II. Using pA, how would you obtain the value of the next element (element 1) of the array? III. Explain in 2-3 sentences what the statement pA = a[1]; would do. IV. Is the...

  • whats the answers How many total integers elements are in an array with 4 rows and...

    whats the answers How many total integers elements are in an array with 4 rows and 7 columns? 07 28 11 What is the resulting array contents, assuming that itemList is an array of size 4 having contents -55, -1, 0, 9? for (i = 0; i < 4; ++i) { itemsList[i] - i; -54,0, 1, 10 O 0, 1, 2, 3 O 1, 2, 3, 4 O-55,-1, 0,9 Given an integer array myVals of size N_SIZE (i.e. int[] myVals...

  • 1. Given the following array, what is the value of pets[3]? var pets = new Array("giraffe",...

    1. Given the following array, what is the value of pets[3]? var pets = new Array("giraffe", "pig", "beetle", "hamster", "spider", "goldfish", "cow"); A. pig B. beetle C. hamster D. spider 2. Given the following array, which statement will create a variable named product that multiplies 4 * 5, using array elements? var nums = new Array(2, 3, 4, 5, 6, 30, 40, 50, 60); A. var product = nums[1] * nums[2]; B. var product = nums[2] * nums[3]; C. var...

  • 2. Use hashing (solve_with_Hash(int[] array, int k)) Initialize a counter variable to O: Insert a...

    2. Use hashing (solve_with_Hash(int[] array, int k)) Initialize a counter variable to O: Insert all elements of array in a hashtable For every element in array: counter0 a. b. c. .Look for array[i] . Look for array [幻 + k in the hash map, if found then increment counter. -k in the hash map, if found then increment counter. Remove arrayli] from hash table. d. return counter For example: Input : array[] {1, 5, 3, 4, 2), k 3 Output:...

  • 10. Which of the following correcthy milites elements each with value 0? super Bass to com...

    10. Which of the following correcthy milites elements each with value 0? super Bass to com I inttl superBass { 0, 0, 0, 0, 0 ); int(1 superBass = new int [5] inttl superBass = new int (5) for (int i = 0; i < super Bass.length superBass ) = 0; +) (A) (B) I only II only I and II only I and III only I. II, and III (D) (E) 17. Consider the following Java program public class...

  • 2. i) Let B be a random variable with the Binomial (n, p) distribution, so that...

    2. i) Let B be a random variable with the Binomial (n, p) distribution, so that Write down the likelihood function L(p) for m independent observations xi,...,Inm 2 marks 6 marks ili) Compute the bias and the mean squared error of the corresponding maximum likeli- from B. Int ii) Show that the maximum likelihood estimate for pis-Σ.ri. mn [7 marks] hood estimator of p. iv) Let X be a continuous random variable with density function for x > 0, and...

  • Question 1 What is the value of x after the following int x = 5; x++;...

    Question 1 What is the value of x after the following int x = 5; x++; x++; x+=x++; A)14 B)10 C)13 D)15 Question 2 The last line in value returning function (before the }) should contain the word return. True False Question 3 This contains three parts: Void or Data Type the name optional parameter list A)Menu System B)Function Header C)Switch Question 4 What is a variable? A)a pointer B)a place in memory to hold data C)int D)a computer programming...

  • Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr,...

    Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr, int count, int key ) { 1: find the index of the first occurance of key. By first occurance we mean lowest index that contains this value. hint: copy the indexOf() method from Lab#3 into the bottom of this project file and call it from inside this remove method. The you will have the index of the value to remove from the array 2:...

  • 1. (10pts) What is the value (in decimal) of X in each case below? Give the...

    1. (10pts) What is the value (in decimal) of X in each case below? Give the expression based on which you arrive at your value. Assume 4 bytes are used to store int and float, 8 for long and double. a. int X b. float X x sizeof[char)/ (float) sizeof10 c. int C- 4: 2. (20pts) Rewrite the following program using macro definitions (adefine) for all the constants and a new type definition (typedef) called Card for all the values...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT