Solved

Which Code Snippet Produces the Sum of the First N

Question 4

Multiple Choice

Which code snippet produces the sum of the first n even numbers? (0 is not considered an even number.)


A) int sum = 0;
For (int i = 1; i <= n; i++)
{
If (i % 2 == 0)
{
Sum = sum + i;
}
}
B) int sum = 0;
For (int i = 1; i <= n; i++)
{
Sum = sum + i * 2;
}
C) int sum = 0;
For (int i = 0; i < n; i++)
{
If (i % 2 == 0)
{
Sum = sum + i;
}
}
D) int sum;
For (int i = 1; i <= n; i++)
{
Sum = sum + i * 2;

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions