Question
Consider the following pseudo-code:Â Â ```
  function calculate(arr):     sum = 0     for i from 0 to length(arr) - 1:       if arr[i] % 2 == 0:         sum = sum + arr[i]       else:         sum = sum - arr[i]     return sum   my_array = [1, 2, 3, 4, 5]   result = calculate(my_array)   print(result)   ```   What will be the output of this code?Solution
Dry Run: Â Â Â Â Â Â `my_array = [1, 2, 3, 4, 5]` Â Â Â Â Â Â `sum = 0` Â Â Â Â Â Â `i = 0, arr[0] = 1` (odd): `sum = 0 - 1 = -1` Â Â Â Â Â Â `i = 1, arr[1] = 2` (even): `sum = -1 + 2 = 1` Â Â Â Â Â Â `i = 2, arr[2] = 3` (odd): `sum = 1 - 3 = -2` Â Â Â Â Â Â `i = 3, arr[3] = 4` (even): `sum = -2 + 4 = 2` Â Â Â Â Â Â `i = 4, arr[4] = 5` (odd): `sum = 2 - 5 = -3` Â Â Â Â Â Â Return `sum = -3`
What is the difference between the total number of leather bags sold by shop A and that by shop C?
If 45 children preferred Apple, how many did choose Orange?
If some people shifted in wing B from wing E and number of people increased by 80% in wing B, then find how much percent people left wing E.
Find the respective ratio of the number of bags sold by shop A on Wednesday and Monday together and the number of bags sold by shop C on Friday and Satu...
What is the approximate average number of vehicles (in thousand) sold by all the companies in the year 2013?
Read the table given below and answer the following question given below.
Number of Students in Five Schools
The number of females travelling by car in city B is what percent of the number of females travelling by car in city A?
Number of umbrellas sold in city B is approximately how much percent of the total number of umbrellas sold in city D?
Find the ratio of the number of chocolates purchased by Sumit from shop C and from shop E.
The number of jackets and shirts produced by company B is how much more/less than the number of shirts produced by company A?