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`
How many countries participated in the International Maritime Defence Expo mentioned in the file?Â
Which organization's Director (Finance) has recently assumed the additional charge of Chairman and Managing Director of the company, according to the in...
On which date did the Border Roads Organisation (BRO) connect the strategic Nimmu-Padam-Darcha road in Ladakh?Â
What was India’s National Index score in the Ipsos Consumer Confidence Survey referenced in the report?Â
Indian Space Research Organisation (ISRO) and IN-SPACe for the successful launch of India's maiden private rocket Vikram-Suborbital developed by ______.
According to the information provided by the Ministry of Defence (MoD),the total value of defence production in the 2022-23 financial year has exceeded ...
The Gyan Bharatam National Manuscript Survey (GBNMS) is planned for a duration of:Â
Bank of Baroda’s UPI-linked credit line for women SHGs provides an overdraft up to:Â
What was the major update from the RBI in the first quarter of FY 2025-26?Â
What was the revised economic growth forecast for India in FY2024-25 as per the latest RBI report?