edited by
250 views
0 votes
0 votes

In the code fragment below, $\text{start}$ and $\text{end}$ are integer values and $\text{square(x)}$ is a function that returns $\text{Ture}$ if $\text{x}$ is a perfect square and $\text{False}$ otherwise.

i := 0;
j := 0;
k :=0;
for m in [start,start+1,...,end]
{
    if(square(m)=True)
    {
        i := i + m*m;
        k := k + m*m;
    }
    else
    {
        j := j + m*2;
        k := k + m*2;
    }
}

At the end of the loop, which of the following are correct statements about the relationship between $\text{i, j}$ and $\text{k}$?

  1. $\text{k = i$\ast$i+j$\ast$2 if (end – start)}$ is even
  2. $\text{k = i$\ast$i+j if (end – start)}$ is odd
  3. $\text{j = k-i if (end – start)}$ is even
  4. $\text{i = k-j if (end – start)}$ is odd
edited by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
1 answer
1
2 votes
2 votes
1 answer
2
soujanyareddy13 asked Jan 29, 2021
445 views
If $P$ is an invertible matrix and $A=PBP^{-1},$ then which of the following statements are necessarily true?$B=P^{-1}AP$$|A|=|B|$$A$ is invertible if and only if $B$ is ...
0 votes
0 votes
3 answers
3
soujanyareddy13 asked Jan 29, 2021
604 views
Let $A=\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}, B=\begin{bmatrix} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \end{bmatrix}, C=\begin{bmatrix} 4 & 5 & 6...
2 votes
2 votes
2 answers
4
soujanyareddy13 asked Jan 29, 2021
374 views
Let $x=\begin{bmatrix} 3& 1 & 2 \end{bmatrix}$. Which of the following statements are true?$x^Tx$ is a $3\times 3$ matrix$xx^T$ is a $3\times 3$ matrix$xx^T$ is a $1\time...