The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+1 vote
54 views

In the code fragment on the right, start and end are integer values and $prime(x)$ is a function that returns true if $x$ is a prime number and $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;
}
}
  1. $k < i+j$
  2. $k = i+j$
  3. $k > i+j$
  4. Depends on $start$ and $end$
asked in Algorithms by Veteran (96.2k points) | 54 views

1 Answer

0 votes

B. $k = i + j$

Whatever be the value of m, the value added to k is also added to exactly one of i and j.

answered by Boss (34.5k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,587 questions
54,197 answers
187,535 comments
71,151 users