190k views
0 votes
A program should compute two times x. Which statement has a logic error?

A. y=x+x;
B. y=2*x;
C. y=x∗2;
D. y=x∗x;

User KingFeming
by
9.0k points

1 Answer

3 votes

Final answer:

Statement D, y=x*x,

has a logic error because it calculates the square of x instead of two times x.

Step-by-step explanation:

The statement that has a logic error is D. y=x*x.

The reason is that this statement is calculating the square of x, not two times x. To compute two times x, you need to use multiplication or addition. A correct statement would be y=2*x.

For example, if x is equal to 3, the correct statement would give you a value of y equal to 6: y=2*3=6.

The statement with a logic error when a program should compute two times x is D. y=x*x. This is because the operation being performed here is multiplication of x by itself, which will give the result of x squared, not x multiplied by 2. The rest of the statements, A. y=x+x, B. y=2*x, and C. y=x*2, are all correct expressions to compute two times x.

User Vitalii Shevchuk
by
7.8k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.