Solved

Which Code Snippet Produces the Sum of the First N

Question 70

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

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents