The Gateway to Computer Science Excellence

+3 votes

In the code fragment on the right, start and end are integer values and $\text{prime}(x)$ is a function that returns true if $x$ is a prime number and $\text{false}$ otherwise. At the end of the loop:

i := 0; j := 0; k := 0; for (m := start; m <= end; m := m+1){ k := k + m; if (prime(m)){ i := i + m; }else{ j := j + m; } }

- $k < i+j$
- $k = i+j$
- $k > i+j$
- Depends on $\text{start}$ and $\text{end}$

+1 vote

__Answer__: B

**Explanation:**

i := 0; j := 0; k := 0; for (m := start; m <= end; m := m+1){ k := k + m; // "k" will have the accumulated sum from start to end. if (prime(m)){ i := i + m; //prime values are added to "m". }else{ j := j + m; //Values which are NOT prime are added to "j". } }

Here,

$\large \color {red}{{\mathrm {\large k}}}$ will contain the sum of all the values from start to end.

$\color {red} {\mathrm {\large i}}$ will contain the sum of values which are __ prime__.

$\color {red} {\mathrm {\large j}}$ will contain the sum of values which are __ NOT__ prime.

Hence, finally the values in k is the sum of values in i and j.

$\therefore$ The relation is: $\color {blue}{\mathrm {\large k = i + j} }$

Hence, **B **is the right option.

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.4k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.2k
- Non GATE 1.4k
- Others 1.4k
- Admissions 595
- Exam Queries 573
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

50,737 questions

57,388 answers

198,578 comments

105,416 users