0

I have this pseudo code that I need to hand trace:

begin
  count <- 1
  while count < 11
    t <- (count ^ 2) - 1
    output t
    count <- count + 1
  endwhile 
end

I am unsure what <- means and I don't really understand what to do with the t. I also keep getting 1,1,1, etc. every time I go through. Any help would be appreciated!

4

2 回答 2

1

首先,运算符的<-意思是“得到”,就像在赋值中一样。所以:

count <- count + 1

表示将变量设置count为 value count + 1

其次,程序将输出 x 2 -1 的前 10 个值,因此:

t <- count^2 - 1

将评估为:

0, 3, 8, 15, 24, 35, 48, 63, 80, 99

对于值count

1, 2, 3, 4, 5, 6, 7, 8, 9, 10

分别。

于 2013-10-07T19:58:47.650 回答
0

这是C ++中的代码,希望对您有所帮助:

int count = 1; // count <- 1
 int t;
 while ( count < 11 ){ // while count < 11
    t = count * count - 1; // t <- (count ^ 2) - 1
    std::cout<<t<<std::endl;  //  output t
    count ++; // count <- count + 1
} //  endwhile 

如上一个答案所述: count 取值:1, 2, 3, 4, 5, 6, 7, 8, 9, 10

并且 t 将采用以下值:0, 3, 8, 15, 24, 35, 48, 63, 80, 99

于 2013-10-07T21:07:54.873 回答