Practical quiz 3

这次测试5和7错了

1.If we have the following description in pseudocode, which will be the value of the variable Y after line 6?

Enter a 1-digit integer number. Example: 8

        1    X <= 1;
        2    Y <= 2;
        3    Z <= 3;
        4    X <= X·Z;
        5    Z <= X - Y;
        6    Y <= X + Y + Z;

6 正确回答

2.Given the following pseudocode, which values will ​​the variables a, b​​, c and d have after the execution of the algorithm?.

Write the results separated by a blank space. Example: if the result at the end of the execution is a = 1, b = 2, c = 23, d = 4, you should answer 1 2 23 4

        a <= 1; b <= 7; c <= 3; d <= 2;
        If (a > 0) AND (c > d) then
            a <= d + c;
          else a <= d * c;
        end if;
        c <= d + a;
        If b = c then
            c <= c + b;
          else c <= c – a;
        end if;
        d <= a + b + c;

5 7 14 26 正确回答

3.Which of the following pseudocodes implements the algorithm that calculates the addition of the even numbers between 1 and 103?

              A <= 2, sum <= 0;
              While A < 102 then
                  sum <= sum + A;
                  A <= A+2;
              end while;

              A <= 1, sum <= 0;
              While A < 102 then
                  sum <= sum + A;
                  A <= A+2;
              end while;



              A <= 1, sum <=0;
              While A < = 103 then
                  sum <= sum + A;
                  A <= A+2;
              end while;



              A <= 2, sum <= 0;
              While A < 103 then
                  sum <= sum + A;
                  A <= A+2;
              end while;


  正确答案4

4.Which of the following pseudocodes implements the algorithm that calculates the addition of the squares of the first 100 natural numbers (from 1 to 100 both included)?.

                For num in 1 to 100 loop
                  total <= total + (num)^2;
                end loop;



                total <= 0;
                For num in 1 to 100 loop
                  total <= num + (num)^2;
                end loop;


                total <= 1;
                For num in 1 to 99 loop
                  total <= total + (num)^2;
                end loop;



                total <= 0;
                For num in 1 to 100 loop
                  total <= total + (num)^2;
                end loop;

 正确的是4

5.Which of the following pseudocodes implements the algorithm that calculates the factorial of a number N?

          factorial <= 1;
          While N > 0 loop
            factorial <= factorial * N;
          N <= N – 1;
          end while;


          factorial <= 1;
          While N ≠ 0 loop
            factorial <= factorial · N;
          N <= N + 1;
          end while;



          factorial <= 1;
          While N ≥ 0 loop
            factorial <= factorial * N;
          N <= N – 1;
          end while;


          factorial <= 1;
          While N > 0 loop
            factorial <= factorial * N;
          N <= N + 1;
          end while;


 6.Given two 8-component vectors: [a0, a1, ……a7] and [b0, b1, ……b7] which of the following pseudocodes computes Y = a0 + b0 + a1 + b1 +…… + a7 + b7 ?



                  for i in 1 to 8 loop
                    acc <= acc + ai + bi;
                  end loop;
                  Y <= acc;


                  acc <= 0;
                  for i in 0 to 7 loop
                    acc <= acc + ai + bi;
                  end loop;Y <= acc;


                  for i in 0 to 7 loop
                    acc <= acc + ai + bi;
                  end loop;
                  Y <= acc;


                  acc <= 0;
                  for i in 0 to 7 loop
                    acc <= acc + ai · bi;
                  end loop;
                  Y <= acc;



     正确答案 2




     7.What will be the value of variable a at the end of the algorithm?

Write the solution as a 2-digit integer number. Example: 59

            a <= 35;
            For i in 0 to 4 loop
               For j in 0 to 4 loop
                  If (i=j) then a <= a + 1;
                     elsif (j = 4) then a <= a + 2;
                     end if;
                  end if;
               end loop;
            end loop;
            a <= a + 10;

   正确答案58

results matching ""

    No results matching ""