1,081 views
3 votes
3 votes

Consider the following function.

Assume that the array contains list of all the numbers from 1 to k –1. What is the return value of function BSR?

  • Sum of all numbers
  • Repeated number in the list
  • Average of all the numbers
  • None of these

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Here I think answer should Be D, None of these, as as per me this program will add up all no from 1 to k-1. i.e. (k-1 * k ) /2 in value & substracting last from it which is also (k-1*k) /2 . So it will always return 0.

Q 37

Made Easy FLT 6-Practice Test 14

2 Answers

2 votes
2 votes

Assume that the array contains list of all the numbers from 1 to k –1. //main line 

i.e. we have two take all no. form 1- k-1 when no. of values are k.

take random input

k= 7

1,2,3,4,5,6,6

now For  loop find sum of all array element= 27

now last = 7(6)/2= 21

return = 27-21= 6

so 6 is repeated.

0 votes
0 votes
Here answer is D) None of the above.

Size of array is k & Array should contain all no from 1 to k-1. So there are k-1 no that must be there. Once we fill up k-1 places with 1 to k-1 no, we get one extra space.

 We can put any No X  there ! (Not necessary to be in 1 to k-1, it is not said that array contains ONLY no from 1 to k-1)

Last = (k * k - 1 ) /2;

value = sum of 1 to k-1 + X = (K * k-1 ) / 2 + X

Value - Last = X

So answer is D.

It seem like B is correct, but it is not so. As we do not need to repeat any no, we can take no outside of given range 1 to k-1  !

Value - Last = Extra no

Related questions

2.2k
views
2 answers
4 votes
Gangani_Son asked Dec 14, 2018
2,199 views
What is the return value of following function for 484? What does it to in general?bool fun(int n){ int sum = 0; for (int odd = 1; n ... it checks whether a given number is perfect square. Any one can explain output of above program?
2.6k
views
4 answers
1 votes
dhairya asked Jul 12, 2016
2,616 views
Consider the following C function: int f(int n) { static int r = 0; If (n < ... } What is the value of f(5)?(A) 3(B) 7(C) 9(D) 18
21
views
1 answers
0 votes
shivamSK asked 17 hours ago
21 views
#include <stdio.h> int main () { int i, k; int a [8] = {33,34,35,36,37,40,50,38}; for(i = 0; i < 3; i++) { a[i] = a[i] + 1; i=i+1; } ... int i = k/2; a[i] = a[i] - 1; } printf ("%d",i+a[i]); }Numerical Answer ______________________________
648
views
2 answers
1 votes
Gopal6854 asked Jul 29, 2023
648 views
In the picture below:Can anyone explain to me why while' loop starting from 2 but in the case of for' loop it is starting from 1 (although i++ is available for ... it is post increment (i++) and in Program 4 it is pre increment (++i).