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`
India celebrated the _____ anniversary of Central Industrial Security Force Raising Day on March 10, 2022.
- Which state recorded the highest retail inflation in March 2025 according to NSO data?
Which of the following public sector company signed a MoU with Greenko ZeroC Private Limited (Greenko) to produce Green Hydrogen?
Exercise Vayushakti-26 was conducted at which location?
Which Union Ministry is responsible for implementing the Pradhan Mantri Awas Yojana (Urban)?
Recently “Tango D10S” is in News. What is this?
Which committee is aimed at promoting the domestic sports manufacturing ecosystem as per the advisory of the Ministry of Youth Affairs & Sports?
What was the growth rate of India's real GDP in Q2 of FY2024-25, as compared to Q1 of the same fiscal year?
Which two Chief Ministers inaugurated the Sidheshwari Temple in Tripura?
_________and Microsoft, has expanded their strategic partnership to help enterprises leverage generative artificial intelligence (AI) and develop joint ...